Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #9589 -- Made development web server more robust in the presenc…

…e of a wider variety of code errors.

Thanks goes to contributor with Trac user 'berto' for the patch.
  • Loading branch information...
commit c2a6b2a43fb8f32cff078c823054e2e65f325464 1 parent b052e6c
Ramiro Morales ramiro authored
Showing with 33 additions and 3 deletions.
  1. +1 −0  AUTHORS
  2. +32 −3 django/utils/autoreload.py
1  AUTHORS
View
@@ -91,6 +91,7 @@ answer newbie questions, and generally made Django that much better:
James Bennett
Danilo Bargen
Shai Berger <shai@platonix.com>
+ berto
Julian Bez
Arvis Bickovskis <viestards.lists@gmail.com>
Natalia Bidart <nataliabidart@gmail.com>
35 django/utils/autoreload.py
View
@@ -28,7 +28,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-import os, sys, time, signal
+import os, sys, time, signal, traceback
try:
from django.utils.six.moves import _thread as thread
@@ -52,10 +52,12 @@
_mtimes = {}
_win = (sys.platform == "win32")
+_error_files = []
+
def code_changed():
global _mtimes, _win
filenames = [getattr(m, "__file__", None) for m in sys.modules.values()]
- for filename in filter(None, filenames):
+ for filename in filter(None, filenames) + _error_files:
if filename.endswith(".pyc") or filename.endswith(".pyo"):
filename = filename[:-1]
if filename.endswith("$py.class"):
@@ -71,9 +73,34 @@ 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, AttributeError):
+ et, ev, tb = sys.exc_info()
+
+ if getattr(ev, 'filename', None) is None:
+ # get the filename from the last item in the stack
+ filename = traceback.extract_tb(tb)[-1][0]
+ else:
+ filename = ev.filename
+
+ if filename not in _error_files:
+ _error_files.append(filename)
+
+ raise
+
+ return wrapper
+
def ensure_echo_on():
if termios:
fd = sys.stdin
@@ -142,5 +169,7 @@ 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.