# -*- coding: utf-8 -*- from mongoengine import connect import tornado.web import tornado.ioloop connection = connect('labs-info') from api import make_app app = make_app() if __name__ == "__main__": app.listen(8080) tornado.ioloop.IOLoop.instance().start()
def main(): parser = argparse.ArgumentParser( description=__doc__, add_help=False, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('-h', '--help', dest='help', help='获取帮助信息', action='store_true', default=False) parser.add_argument('-d', '--debug', dest='debug', help='调试模式,\ 出错自动重载及完整错误信息,默认 False', action='store_true', default=False) parser.add_argument('-r', '--reload', dest='auto_reload', help='自动重载,' \ '出错或者代码更新自动重载默认False', action='store_true', default=False) parser.add_argument('-p', '--port', dest='port', help='指定绑定端口,默认为 9090', default=9090, type=int) parser.add_argument('-b', '--host', dest='host', help='指定绑定地址,默认为 127.0.0.1', default=None) args = parser.parse_args() if args.help: parser.print_help() print("\n示例") print(' 指定绑定端口 %s -p 80' % sys.argv[0]) print(' 指定绑定地址为所有地址 %s --host 0.0.0.0 --port 80' % sys.argv[0]) print('') else: from api import make_app app = make_app() if args.debug: app.run(host=args.host, port=args.port, debug=args.debug, threaded=True) else: from gevent import pywsgi import werkzeug.serving def run_wsgi_server(): if args.host is None: args.host = '127.0.0.1' print('* Running on http://{0}:{1}/ (Press CTRL+C to quit)'. format(args.host, args.port)) server = pywsgi.WSGIServer((args.host, args.port), app) server.serve_forever() # 自动重载 if args.auto_reload: run_wsgi_server = werkzeug.serving.run_with_reloader( run_wsgi_server) run_wsgi_server()
def get_app(self): return api.make_app()
if args.debug: app.run(host=args.host, port=args.port, debug=args.debug, threaded=True) else: from gevent import pywsgi import werkzeug.serving def run_wsgi_server(): if args.host is None: args.host = '127.0.0.1' print('* Running on http://{0}:{1}/ (Press CTRL+C to quit)'. format(args.host, args.port)) server = pywsgi.WSGIServer((args.host, args.port), app) server.serve_forever() # 自动重载 if args.auto_reload: run_wsgi_server = werkzeug.serving.run_with_reloader( run_wsgi_server) run_wsgi_server() if __name__ == '__main__': main() else: from api import make_app application = make_app() # from api.controller import order
def get_app(self): self.app = app = make_app(debug=False) app.db = MagicMock() return app