Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python + Tornado Restart after editing files

I just start learning Python + Tornado for my web servers. Every time I modify some code on my python scripts or templates I have to stop the in my terminal (CTRL+C) and restart it (python server.py) and I want a more effective way to do this, that after modifying code in some files the server automatically restarts.

Previously I working with NodeJS and using supervisor to do this.

Also there is a way to reload my tab in Google Chrome so I can see the changes without reloading (F5)

Currently I'm using Ubuntu 11.10 and Sublime Text 2 and using CTRL+B on sublime text, but if the server is already running generates an error because the address and port is in use. There is a fix for that without changing the port.

Thanks.

like image 672
danielfrg Avatar asked Apr 01 '12 02:04

danielfrg


2 Answers

If you are looking for automatic reloading of .py files during development. In your tornado.web.Application() put debug=True after your handlers.

I don't think you should do this in production environment, because such implementation typically use a background thread to actively scan files for changes, which may slow down your application.

like image 112
He Shiming Avatar answered Oct 13 '22 00:10

He Shiming


You need to turn autoreload on:

tornado.autoreload.start()
tornado.autoreload.watch('myfile')

Complete example at https://gist.github.com/renaud/10356841

like image 40
Renaud Avatar answered Oct 12 '22 23:10

Renaud