]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Watch the main module for tornado.autoreload's -m mode
authorBen Darnell <ben@bendarnell.com>
Mon, 29 Aug 2011 01:42:35 +0000 (18:42 -0700)
committerBen Darnell <ben@bendarnell.com>
Mon, 29 Aug 2011 01:42:35 +0000 (18:42 -0700)
tornado/autoreload.py

index 20c5663af94f61fa81d800e058b4ca4fe051b35c..bdd46b7a078f2ae41d5337217bcd9a601b5563dd 100644 (file)
@@ -31,6 +31,7 @@ from __future__ import with_statement
 import functools
 import logging
 import os
+import pkgutil
 import sys
 import types
 import subprocess
@@ -221,6 +222,12 @@ def main():
         logging.info("Script exited normally")
     # restore sys.argv so subsequent executions will include autoreload
     sys.argv = original_argv
+
+    if mode == 'module':
+        # runpy did a fake import of the module as __main__, but now it's
+        # no longer in sys.modules.  Figure out where it is and watch it.
+        watch(pkgutil.get_loader(module).get_filename())
+
     wait()