tornado 多进程模式 tornado 多进程模式解析

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

tornado 多进程模式 tornado 多进程模式解析

mingz2013   2021-03-28 我要评论
想了解tornado 多进程模式解析的相关内容吗,mingz2013在本文为您仔细讲解tornado 多进程模式的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:tornado,多进程,python,tornado多进程,tornado,源码解析,下面大家一起来学习吧。

本文主要研究的是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 多进程模式解析的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们