tornado 多进程模式解析,tornado进程解析
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 多进程模式解析的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!
相关内容
- 100行python代码实现跳一跳辅助程序,100行python
- selenium python浏览器多窗口处理代码示例,seleniumpython
- Python编程二分法实现冒泡算法+快速排序代码示例,py
- Python3一行代码实现图片文字识别的示例,
- python逆向入门教程,python入门教程
- 使用python编写简单的小程序编译成exe跑在win10上,pyth
- Python操作mysql数据库实现增删查改功能的方法,pythonm
- Python实现可获取网易页面所有文本信息的网易网络爬虫
- 使用Python实现windows下的抓包与解析,pythonwindows
- Tornado高并发处理方法实例代码,tornado处理方法
评论关闭