Is there a way to deploy new code with Tornado / Python without restarting the server?

I recently started experimenting with the web server / Python infrastructure and Tornado for web development. I used to use PHP with my own infrastructure on the LAMP stack. With PHP, deploying updated code / new code is as easy as uploading it to the server due to the interaction of mod_php and Apache.

When I add new code or update code in Python / Tornado, do I need to restart the Tornado server? I saw that this is problematic if you have several active users.

(a) Should I reboot the server, or is there another / better way?

(b) If so, how can I avoid disconnecting users / getting errors / etc. upon restart (which may take a few seconds)?

[One possible consideration is to use a page flipping paradigm with Nginx pointing to the server, starting a new server instance with updated code, redirecting Nginx, and deleting the original server ...?]

+6
source share
4 answers

It seems like the best way is to use Nginx with multiple instances of Tornado, as I mentioned in my original question, and as Cole says. Nginx can reload its configuration file on the fly. Thus, the process is as follows:

  • Update Python / Tornado Web Application Code
  • Launch a new application instance on a different port.
  • Update the Nginx configuration file to point to the new instance (first check the syntax of the configuration file)
  • Reload the Nginx configuration file with kill -HUP
  • Stop old Python / Tornado web server instance

Some useful resources on Nginx regarding hot swapping of a configuration file:

https://calomel.org/nginx.html (in the section "Explanation of directives in nginx.conf") http://wiki.nginx.org/CommandLine (in the section "Downloading a new configuration using signals")

+9
source

Use HAProxy or Nginx and proxies for several Tornado processes, which can then be restarted one at a time. Tornado docs span Nginx , but it does not support web ports, so if you use them, you will need HAProxy.

+1
source

You can use the debug = True switch with a web tornado instance.

 T_APP = tornado.web.Application(<URL_MAP>, debug=True) 

This reflects changes to the handler as and when they happen.

0
source

Is this what you are looking for?

Module for automatically restarting the server when the module changes. http://www.tornadoweb.org/en/branch2.4/autoreload.html

0
source

Source: https://habr.com/ru/post/901249/


All Articles