tornado多进程模式的示例分析

发布时间:2021-09-09 15:02:03 作者:小新
来源:亿速云 阅读:107

这篇文章给大家分享的是有关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多进程模式的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

推荐阅读:
  1. python多进程并发的示例分析
  2. python中多进程并行的示例分析

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python tornado

上一篇:spring-cloud-kubernetes的源码怎么导入到IntelliJ中

下一篇:怎么通过重启路由的方法切换IP地址

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》