Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added checking error files for modifications

When a syntax error or indentation error occurs, the autoreloader no
longer checks that file because it's not found in sys.modules.  In
order to monitor these files, add them to the _error_files list.
  • Loading branch information...
commit 970cee879c84eb495f385822e4e9c99f2aed2088 1 parent b8340d2
@ebas authored
Showing with 20 additions and 3 deletions.
  1. +20 −3 django/utils/autoreload.py
View
23 django/utils/autoreload.py
@@ -51,10 +51,11 @@
_mtimes = {}
_win = (sys.platform == "win32")
+_error_files = []
def code_changed():
global _mtimes, _win
- for filename in filter(lambda v: v, map(lambda m: getattr(m, "__file__", None), sys.modules.values())):
+ for filename in filter(lambda v: v, map(lambda m: getattr(m, "__file__", None), sys.modules.values())) + _error_files:
if filename.endswith(".pyc") or filename.endswith(".pyo"):
filename = filename[:-1]
if filename.endswith("$py.class"):
@@ -70,9 +71,25 @@ def code_changed():
continue
if mtime != _mtimes[filename]:
_mtimes = {}
+ try:
+ del _error_files[_error_files.index(filename)]
+ except ValueError: pass
return True
return False
+def check_errors(fn):
+ def wrapper(*args, **kwargs):
+ try:
+ fn(*args, **kwargs)
+ except (ImportError, IndentationError, NameError,
+ SyntaxError, TypeError), msg:
+ et, ev, tb = sys.exc_info()
+ if ev.filename not in _error_files:
+ _error_files.append(ev.filename)
+
+ raise
+ return wrapper
+
def ensure_echo_on():
if termios:
fd = sys.stdin
@@ -141,5 +158,5 @@ def main(main_func, args=None, kwargs=None):
reloader = jython_reloader
else:
reloader = python_reloader
- reloader(main_func, args, kwargs)
-
+ wrapped_main_func = check_errors(main_func)
+ reloader(wrapped_main_func, args, kwargs)
Please sign in to comment.
Something went wrong with that request. Please try again.