diff options
| author | Tim Graham <timograham@gmail.com> | 2017-09-07 08:16:21 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-07 08:16:21 -0400 |
| commit | 6e4c6281dbb7ee12bcdc22620894edb4e9cf623f (patch) | |
| tree | 1c21218d4b6f00c499f18943d5190ebe7b5248c9 /django/utils/autoreload.py | |
| parent | 8b2515a450ef376b9205029090af0a79c8341bd7 (diff) | |
Reverted "Fixed #27818 -- Replaced try/except/pass with contextlib.suppress()."
This reverts commit 550cb3a365dee4edfdd1563224d5304de2a57fda
because try/except performs better.
Diffstat (limited to 'django/utils/autoreload.py')
| -rw-r--r-- | django/utils/autoreload.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py index a872d42d65..2784a89aeb 100644 --- a/django/utils/autoreload.py +++ b/django/utils/autoreload.py @@ -34,7 +34,6 @@ import subprocess import sys import time import traceback -from contextlib import suppress import _thread @@ -44,8 +43,10 @@ from django.core.signals import request_finished # This import does nothing, but it's necessary to avoid some race conditions # in the threading module. See http://code.djangoproject.com/ticket/2330 . -with suppress(ImportError): +try: import threading # NOQA +except ImportError: + pass try: import termios @@ -53,7 +54,7 @@ except ImportError: termios = None USE_INOTIFY = False -with suppress(ImportError): +try: # Test whether inotify is enabled and likely to work import pyinotify @@ -61,6 +62,8 @@ with suppress(ImportError): if fd >= 0: USE_INOTIFY = True os.close(fd) +except ImportError: + pass RUN_RELOADER = True @@ -207,8 +210,10 @@ def code_changed(): continue if mtime != _mtimes[filename]: _mtimes = {} - with suppress(ValueError): + try: del _error_files[_error_files.index(filename)] + except ValueError: + pass return I18N_MODIFIED if filename.endswith('.mo') else FILE_MODIFIED return False @@ -287,15 +292,19 @@ def restart_with_reloader(): def python_reloader(main_func, args, kwargs): if os.environ.get("RUN_MAIN") == "true": _thread.start_new_thread(main_func, args, kwargs) - with suppress(KeyboardInterrupt): + try: reloader_thread() + except KeyboardInterrupt: + pass else: - with suppress(KeyboardInterrupt): + try: exit_code = restart_with_reloader() if exit_code < 0: os.kill(os.getpid(), -exit_code) else: sys.exit(exit_code) + except KeyboardInterrupt: + pass def jython_reloader(main_func, args, kwargs): |
