From: Ben Darnell Date: Mon, 29 Aug 2011 01:42:35 +0000 (-0700) Subject: Watch the main module for tornado.autoreload's -m mode X-Git-Tag: v2.1.0~38 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=129d77d67323386b3af29144ec139973137b3fda;p=thirdparty%2Ftornado.git Watch the main module for tornado.autoreload's -m mode --- diff --git a/tornado/autoreload.py b/tornado/autoreload.py index 20c5663af..bdd46b7a0 100644 --- a/tornado/autoreload.py +++ b/tornado/autoreload.py @@ -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()