https://www.douban.com/note/217901726/
app
官方文檔的helloworld實例中的啓動方法:tornado
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()
須要注意的一點是,要關掉debug模式,不然:
[E 110521 11:26:53 httpserver:229] Cannot run in multiple processes: IOLoop instance has already been initialized. You cannot call IOLoop.instance() before calling start()
緣由是,autoreload.py已經在http_server.start()以前就初始化了IOLoop,這個在httpserver.py中的class HTTPServer()和def start()的doc string中已經解釋了。oop