Tornado 多进程模式

来源:互联网 发布:兰州文理学院网络教学 编辑:程序博客网 时间:2024/05/16 12:21

官方文档的helloworld实例中的启动方法:

    if __name__ == "__main__":            application.listen(8888)     # listen is a shortcut for bind and start ,这点看httpserver.py可以得知        tornado.ioloop.IOLoop.instance().start()

并且在listen中,将tornado启动为单进程模型。

所以要启动为多进程模型的方法为:摒弃listen方法

    http_server = tornado.httpserver.HTTPServer(application)    http_server.bind(options.port, options.host)    http_server.start(num_processes=0) # tornado将按照cpu核数来fork进程    tornado.ioloop.IOLoop.instance().start()

需要注意是,

1. 关掉debug模式

 settings = {'debug' : False}

2.只有在linux上才能开启多进程模式

原创粉丝点击