Skip to content

Commit

Permalink
Improve autoreload for import-time errors.
Browse files Browse the repository at this point in the history
We already had a special case for SyntaxErrors, but NameErrors and other
import-time errors could leave a file unwatched.
  • Loading branch information
bdarnell committed Sep 2, 2012
1 parent df620e4 commit fd9bcb2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tornado/autoreload.py
Expand Up @@ -71,6 +71,7 @@
import os
import pkgutil
import sys
import traceback
import types
import subprocess

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit fd9bcb2

Please sign in to comment.