tornado 多进程模式解析
作者:mingz2013 时间:2021-01-20 10:56:44
本文主要研究的是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中已经解释了。
来源:http://blog.csdn.net/mingzznet/article/details/52929743
标签:python,tornado,多进程
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python接口自动化之浅析requests模块post请求
2022-12-10 21:10:05
![](https://img.aspxhome.com/file/2023/0/87740_0s.png)
Python基础之变量的相关知识总结
2021-05-09 00:16:06
通过分析SQL语句的执行计划优化SQL
2011-10-24 20:03:20
Python实现钉钉订阅消息功能
2023-02-23 05:25:08
![](https://img.aspxhome.com/file/2023/4/67854_0s.jpg)
Python 实现训练集、测试集随机划分
2023-02-12 01:41:24
![](https://img.aspxhome.com/file/2023/8/76898_0s.jpg)
JavaScript开发时的五个小提示
2007-11-21 19:54:00
CSS结合js实现动态更换皮肤
2007-07-14 10:01:00
python如何发布自已pip项目的方法步骤
2023-01-22 01:17:36
asp函数InstrRev()介绍及获取文件名例子
2007-11-19 19:01:00
如何使用微信公众平台开发模式实现多客服
2023-11-14 17:48:37
PyQt5的相对布局管理的实现
2022-02-23 08:11:18
![](https://img.aspxhome.com/file/2023/9/86199_0s.png)
使用python绘制常用的图表
2022-02-16 19:47:33
![](https://img.aspxhome.com/file/2023/1/94051_0s.jpg)
Python编程之变量赋值操作实例分析
2021-09-20 12:12:01
提升Python程序运行效率的6个方法
2023-08-23 08:36:46
新年伊始,看各大网站新春LOGO
2009-01-01 19:35:00
![](https://img.aspxhome.com/file/UploadPic/20091/1/114040f01010p00001031-53s.gif)
Django零基础入门之模板变量详解
2023-03-19 11:17:16
![](https://img.aspxhome.com/file/2023/2/82722_0s.jpg)
Python使用OpenPyXL处理Excel表格
2022-07-29 21:10:21
![](https://img.aspxhome.com/file/2023/1/87791_0s.png)
Python Decorator装饰器的创建方法及常用场景分析
2022-05-05 03:34:11
Python爬取12306车次信息代码详解
2022-05-19 03:42:00
![](https://img.aspxhome.com/file/2023/3/103333_0s.png)
tensorflow实现读取模型中保存的值 tf.train.NewCheckpointReader
2022-08-21 05:25:51
![](https://img.aspxhome.com/file/2023/9/76169_0s.jpg)