I googled and found a hint that I should set debug mode in Tornado so that it could reload files automatically on update. But I didn't find an exact string to insert. I tried different combinations similar to this application.settings = {"Debug": True}
but it doesn't help.
Asked
Active
Viewed 1.7k times
14

Sergei Basharov
- 379
- 2
- 4
- 13
-
i think it should be {"debug":True} – jondinham Mar 02 '12 at 05:52
2 Answers
15
Here's a tweaked example from the tornado site:
if __name__ == "__main__":
application = tornado.web.Application([
(r"/", MainHandler)
], debug=True)
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()

Jon Haddad
- 1,372
- 3
- 13
- 20
-
2"debug=True" has to be outside of the list of handlers for it to work---like this: "...],debug=True)" – Hemm Apr 17 '12 at 04:18
-
Good catch, I had written it without checking it. Updated my answer accordingly. – Jon Haddad May 01 '12 at 20:01
0
For those who like the debug=True
option and using Tornado-multiprocess the following error will be raised:
Traceback (most recent call last):
File "./main.py", line 54, in <module>
server.start(0) # forks one process per cpu
File "/Users/me/Library/Python/2.7/lib/python/site-packages/tornado/tcpserver.py", line 221, in start
process.fork_processes(num_processes)
File "/Users/me/Library/Python/2.7/lib/python/site-packages/tornado/process.py", line 130, in fork_processes
raise RuntimeError("Cannot run in multiple processes: IOLoop instance "
RuntimeError: Cannot run in multiple processes: IOLoop instance has already been initialized. You cannot call IOLoop.instance() before calling start_processes()
This is because debug=True
load IOLoop
and it cannot be loaded twice.
According to the documentation
Setting debug=True is equivalent to autoreload=True, compiled_template_cache=False, static_hash_cache=False, serve_traceback=True.
So when using debug=True
Tornado also sets ( for convenience ) another flag: autoreload=True
which "watch" for changes and reload the server.
The autoreload
option is the one that cannot be turned on when using multi-process.
So you need to configure it like so:
if __name__ == "__main__":
application = tornado.web.Application([
(r"/", MainHandler)
], debug=True, autoreload=False)
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()

Ricky Levi
- 135
- 7