12

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.

danielfrg
  • 2,597
  • 2
  • 22
  • 23

2 Answers2

12

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.

He Shiming
  • 5,710
  • 5
  • 38
  • 68
  • 1
    Actually I believe tornado does not use a separate thread for this but instead registers handlers on its IOLoop. Nevertheless it incurs an overhead. Also, debug messages should not be used in production anyway. – Eren Güven Sep 15 '12 at 13:59
  • It's possible just to pass in "autoreload=True" now. And there is a documentation page here: http://www.tornadoweb.org/en/stable/autoreload.html – Ross Dec 01 '16 at 10:18
5

You need to turn autoreload on:

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

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

Renaud
  • 16,073
  • 6
  • 81
  • 79