您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

tornado 多进程模式解析

5b51 2022/1/14 8:15:31 python 字数 2103 阅读 298 来源 www.jb51.cc/python

本文主要研究的是tornado多进程模式的相关内容,具体如下。 官方文档的helloworld实例中的启动方法:

概述

本文主要研究的是tornado 多进程模式的相关内容,具体如下。

官方文档的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()

需要注意的一点是,要关掉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中已经解释了。

总结

以上就是本文关于tornado 多进程模式解析的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持

总结

以上是编程之家为你收集整理的tornado 多进程模式解析全部内容,希望文章能够帮你解决tornado 多进程模式解析所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶