diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index 8d9d6f2..011f7ab 100644
a
|
b
|
|
28 | 28 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 | 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | 30 | |
31 | | import os, sys, time |
| 31 | import os, sys, time, traceback |
32 | 32 | |
33 | 33 | try: |
34 | 34 | import thread |
… |
… |
RUN_RELOADER = True
|
48 | 48 | _mtimes = {} |
49 | 49 | _win = (sys.platform == "win32") |
50 | 50 | |
| 51 | _error_files = [] |
| 52 | |
51 | 53 | def code_changed(): |
52 | 54 | global _mtimes, _win |
53 | | for filename in filter(lambda v: v, map(lambda m: getattr(m, "__file__", None), sys.modules.values())): |
| 55 | for filename in filter(lambda v: v, map(lambda m: getattr(m, "__file__", None), sys.modules.values())) + _error_files: |
54 | 56 | if filename.endswith(".pyc") or filename.endswith(".pyo"): |
55 | 57 | filename = filename[:-1] |
56 | 58 | if not os.path.exists(filename): |
… |
… |
def code_changed():
|
64 | 66 | continue |
65 | 67 | if mtime != _mtimes[filename]: |
66 | 68 | _mtimes = {} |
| 69 | try: |
| 70 | del _error_files[_error_files.index(filename)] |
| 71 | except ValueError: pass |
67 | 72 | return True |
68 | 73 | return False |
69 | 74 | |
| 75 | def check_errors(fn): |
| 76 | def wrapper(*args, **kwargs): |
| 77 | try: |
| 78 | fn(*args, **kwargs) |
| 79 | except (ImportError, IndentationError, |
| 80 | NameError, SyntaxError, TypeError), msg: |
| 81 | et, ev, tb = sys.exc_info() |
| 82 | |
| 83 | if getattr(ev, 'filename', None) is None: |
| 84 | # get the filename from the last item in the stack |
| 85 | filename = traceback.extract_tb(tb)[-1][0] |
| 86 | else: |
| 87 | filename = ev.filename |
| 88 | |
| 89 | if filename not in _error_files: |
| 90 | _error_files.append(filename) |
| 91 | |
| 92 | raise |
| 93 | |
| 94 | return wrapper |
| 95 | |
70 | 96 | def reloader_thread(): |
71 | 97 | while RUN_RELOADER: |
72 | 98 | if code_changed(): |
… |
… |
def main(main_func, args=None, kwargs=None):
|
115 | 141 | reloader = jython_reloader |
116 | 142 | else: |
117 | 143 | reloader = python_reloader |
118 | | reloader(main_func, args, kwargs) |
| 144 | |
| 145 | wrapped_main_func = check_errors(main_func) |
| 146 | reloader(wrapped_main_func, args, kwargs) |
119 | 147 | |