From: Ben Darnell Date: Sun, 2 Sep 2012 16:55:31 +0000 (-0700) Subject: Improve autoreload for import-time errors. X-Git-Tag: v3.0.0~263^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd9bcb2e11a5299a4e63e8a7017c435d098b1fec;p=thirdparty%2Ftornado.git Improve autoreload for import-time errors. We already had a special case for SyntaxErrors, but NameErrors and other import-time errors could leave a file unwatched. --- diff --git a/tornado/autoreload.py b/tornado/autoreload.py index 55a10d10c..940c2be7a 100644 --- a/tornado/autoreload.py +++ b/tornado/autoreload.py @@ -71,6 +71,7 @@ import logging import os import pkgutil import sys +import traceback import types import subprocess @@ -275,7 +276,16 @@ def main(): logging.info("Script exited with status %s", e.code) except Exception, e: logging.warning("Script exited with uncaught exception", exc_info=True) + # If an exception occurred at import time, the file with the error + # never made it into sys.modules and so we won't know to watch it. + # Just to make sure we've covered everything, walk the stack trace + # from the exception and watch every file. + for (filename, lineno, name, line) in traceback.extract_tb(sys.exc_info()[2]): + watch(filename) if isinstance(e, SyntaxError): + # SyntaxErrors are special: their innermost stack frame is fake + # so extract_tb won't see it and we have to get the filename + # from the exception object. watch(e.filename) else: logging.info("Script exited normally")