manager.py 1.93 KB
Newer Older
wanli's avatar
wanli committed
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
# -*- coding: utf-8 -*-
from gevent import monkey
monkey.patch_all()
import logging
from tornado.wsgi import WSGIContainer
from tornado.web import Application, FallbackHandler
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from flask_script import Manager
from flask_migrate import Migrate
from multiprocessing import cpu_count
from application.app import create_app, db
from application.config import config

# 根据配置初始化app
app = create_app(config)
migrate = Migrate(app, db)
manager = Manager(app)

@manager.command
def run():
    """
    生产模式启动命令函数
    To use: python3 manager.py run
    """
    # app.logger.setLevel(app.config.get('LOG_LEVEL', logging.INFO))
    # service_config = {
    #     'bind': app.config.get('BIND', '0.0.0.0:3000'),
    #     'workers': app.config.get('WORKERS', cpu_count() * 2 + 1),
    #     'worker_class': 'gevent',
    #     'worker_connections': app.config.get('WORKER_CONNECTIONS', 10000),
    #     'backlog': app.config.get('BACKLOG', 2048),
    #     'timeout': app.config.get('TIMEOUT', 60),
    #     'loglevel': app.config.get('LOG_LEVEL', 'info'),
    #     'pidfile': app.config.get('PID_FILE', 'run.pid'),
    # }

    http_server = HTTPServer(WSGIContainer(app))
    http_server.listen(3000, address='127.0.0.1')
wanliofficial's avatar
wanliofficial committed
40
<<<<<<< HEAD
wanli's avatar
wanli committed
41 42 43 44 45 46

    # wsgi_app = WSGIContainer(app)
    # application = Application([
    #     (r'.*', FallbackHandler, dict(fallback=wsgi_app))
    # ], **service_config)
    # application.listen(3000)
wanliofficial's avatar
wanliofficial committed
47 48
=======
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca
wanli's avatar
wanli committed
49 50 51 52 53 54 55 56 57 58
    IOLoop.instance().start()


@manager.command
def debug():
    """
    debug模式启动命令函数
    To use: python3 manager.py debug
    """
    # app.logger.setLevel(logging.DEBUG)
wanliofficial's avatar
wanliofficial committed
59
<<<<<<< HEAD
wanli's avatar
wanli committed
60
    print("start from here......")
wanliofficial's avatar
wanliofficial committed
61 62
=======
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca
wanli's avatar
wanli committed
63 64 65 66
    app.run(debug=True, port=3000, host='127.0.0.1')

if __name__ == '__main__':
    manager.run()