代码拉取完成,页面将自动刷新
同步操作将从 qd-today/qd 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2016 Binux <roy@binux.me>
import asyncio
import json
import logging
import os
import platform
import sys
import tornado.log
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop, PeriodicCallback
import config
from db import DB, db_converter
from db.basedb import engine
from libs.log import Log
from web.app import Application
from worker import BatchWorker, QueueWorker
def start_server():
if sys.getdefaultencoding() != 'utf-8':
import importlib
importlib.reload(sys)
# init logging
logger = Log().getlogger()
logger_QD = Log('QD.Run').getlogger()
if config.debug:
channel = logging.StreamHandler(sys.stderr)
channel.setFormatter(tornado.log.LogFormatter())
channel.setLevel(logging.WARNING)
logger_QD.addHandler(channel)
if not config.accesslog:
tornado.log.access_log.disabled = True
else:
tornado.log.access_log = Log('tornado.access').getlogger()
# tornado.log.app_log = Log('tornado.application').getlogger()
if len(sys.argv) > 2 and sys.argv[1] == '-p' and sys.argv[2].isdigit():
port = int(sys.argv[2])
else:
port = config.port
if platform.system() == 'Windows':
config.multiprocess = False
if config.multiprocess and config.autoreload:
config.autoreload = False
try:
database = DB()
converter = db_converter.DBconverter(database)
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
run = asyncio.ensure_future(converter.ConvertNewType(database) , loop=loop)
loop.run_until_complete(run)
default_version = json.load(open(os.path.join(os.path.dirname(__file__), 'version.json'),'r', encoding='utf-8'))['version']
App= Application(database, default_version)
http_server = HTTPServer(App, xheaders=True)
http_server.bind(port, config.bind)
if config.multiprocess:
http_server.start(num_processes=0)
else:
http_server.start()
io_loop = IOLoop.instance()
try:
if config.worker_method.upper() == 'QUEUE':
worker = QueueWorker(database)
io_loop.add_callback(worker)
elif config.worker_method.upper() == 'BATCH':
worker = BatchWorker(database)
PeriodicCallback(worker, config.check_task_loop).start()
else:
raise Exception('worker_method must be Queue or Batch, please check config!')
except Exception as e:
logger.exception('worker start error!')
raise KeyboardInterrupt()
logger_QD.info("Http Server started on %s:%s", config.bind, port)
io_loop.start()
except KeyboardInterrupt :
logger_QD.info("Http Server is being manually interrupted... ")
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
run = asyncio.ensure_future(engine.dispose() , loop=loop)
loop.run_until_complete(run)
logger_QD.info("Http Server is ended. ")
if __name__ == "__main__":
start_server()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。