tornado multi process pattern parsing

  • 2020-06-23 01:08:59
  • OfStack

This paper mainly studies the related contents of tornado multi-process mode, which are as follows.

The boot method in the helloworld instance of the official document:


if __name__ == "__main__":

application. (8888) # listen is shortcut bind and start


 tornado.ioloop.IOLoop.instance().start()

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

So the way to start a multi-process model is to get rid of the listen method


http_server = tornado.httpserver.HTTPServer(application)

  http_server.bind(options.port, options.host)

  http_server.start(num_processes=0) # tornado Will be in accordance with the cpu Auditing to fork process 

  tornado.ioloop.IOLoop.instance().start()

One thing to note is to turn off the 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 ES35en.py has already initialized IOLoop before ES37en_server.start (), which is explained in ES41en.py class HTTPServer() and def start().

conclusion

That's the end of this article on tornado multiprocess schema parsing, and I hope it's helpful. Interested friends can continue to refer to other related topics in this site, if there is any deficiency, welcome to comment out. Thank you for your support!


Related articles: