Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of tornado Multi-process Mode

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you the content of a sample analysis of the tornado multi-process model. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The details are as follows.

Startup method in the helloworld instance of the official document:

If _ name__ = = "_ _ main__":

Application.listen (8888) # listen is a shortcut for bind and start, which can be seen from httpserver.py.

Tornado.ioloop.IOLoop.instance () .start ()

And in listen, start tornado as a single-process model.

So the way to start as a multi-process model is to abandon the listen method

Http_server = tornado.httpserver.HTTPServer (application) http_server.bind (options.port, options.host) http_server.start (num_processes=0) # tornado will fork the process tornado.ioloop.IOLoop.instance () .start () according to the number of fork cores

One thing to note is to turn off debug mode, otherwise:

[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 ()

The reason is that autoreload.py initializes IOLoop before http_server.start (), which is explained in the doc string of class HTTPServer () and def start () in httpserver.py.

Thank you for reading! This is the end of this article on "sample Analysis of tornado Multi-process Mode". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report