forked from qd-today/qd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·63 lines (53 loc) · 1.79 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2016 Binux <[email protected]>
import sys
import platform
import logging
import tornado.log
from tornado.ioloop import IOLoop, PeriodicCallback
from tornado.httpserver import HTTPServer
import config
from web.app import Application
from worker import MainWorker
from db import sqlite3_db_task_converter
import requests
requests.packages.urllib3.disable_warnings()
if __name__ == "__main__":
if sys.getdefaultencoding() != 'utf-8':
import importlib
importlib.reload(sys)
# init logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG if config.debug else logging.INFO)
channel = logging.StreamHandler(sys.stdout)
channel.setFormatter(tornado.log.LogFormatter())
logger.addHandler(channel)
if not config.debug:
channel = logging.StreamHandler(sys.stderr)
channel.setFormatter(tornado.log.LogFormatter())
channel.setLevel(logging.WARNING)
logger.addHandler(channel)
if len(sys.argv) > 2 and sys.argv[1] == '-p' and sys.argv[2].isdigit():
port = int(sys.argv[2])
else:
port = config.port
converter = sqlite3_db_task_converter.DBconverter()
converter.ConvertNewType()
if platform.system() == 'Windows':
config.multiprocess = False
if config.multiprocess and config.autoreload:
config.autoreload = False
http_server = HTTPServer(Application(), xheaders=True)
http_server.bind(port, config.bind)
if config.multiprocess:
http_server.start(num_processes=0)
else:
http_server.start()
worker = MainWorker()
PeriodicCallback(worker, config.check_task_loop).start()
worker()
logging.info("http server started on %s:%s", config.bind, port)
IOLoop.instance().start()