加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

tornado 多进程模式解析

发布时间:2020-12-17 07:32:52 所属栏目:Python 来源:网络整理
导读:本文主要研究的是tornado 多进程模式的相关内容,具体如下。 官方文档的helloworld实例中的启动方法: if __name__ == "__main__": application.listen(8888) # listen is a shortcut for bind and start ,这点看httpserver.py可以得知 tornado.ioloop.IOLo

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

您可能感兴趣的文章:

  • Python tornado队列示例-一个并发web爬虫代码分享
  • Tornado协程在python2.7如何返回值(实现方法)
  • 深入解析Python的Tornado框架中内置的模板引擎
  • 使用Python的Tornado框架实现一个Web端图书展示页面
  • 为Python的Tornado框架配置使用Jinja2模板引擎的方法
  • Python的Tornado框架实现异步非阻塞访问数据库的示例
  • Python的Tornado框架实现图片上传及图片大小修改功能

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读