I ran it on Python 3.7.6 and Python 3.8.2 and found the deadlock issue on both.
I then adjusted the settings to *only* have the console logger, and added these lines at the end of the settings file:
import faulthandler
faulthandler.enable()
print(os.getpid())
Then used `runserver`, ran until the deadlock, and killed the *second* printed PID with `kill -ABRT` . This kills the actual Django server process, rather than the outer "watch & restart" process.
This ended with a traceback with lots of threads all trying to acquire a lock. Some are trying to log at the end of the request:
Thread 0x000070000cecf000 (most recent call first):
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/logging/__init__.py", line 221 in _acquireLock
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/logging/__init__.py", line 1687 in isEnabledFor
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/logging/__init__.py", line 1433 in info
File "/Users/chainz/Documents/Projects/wedge/venv38/lib/python3.8/site-packages/django/core/servers/basehttp.py", line 157 in log_message
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/http/server.py", line 544 in log_request
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/wsgiref/simple_server.py", line 34 in close
File "/Users/chainz/Documents/Projects/wedge/venv38/lib/python3.8/site-packages/django/core/servers/basehttp.py", line 114 in close
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/wsgiref/handlers.py", line 196 in finish_response
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/wsgiref/handlers.py", line 138 in run
File "/Users/chainz/Documents/Projects/wedge/venv38/lib/python3.8/site-packages/django/core/servers/basehttp.py", line 197 in handle_one_request
File "/Users/chainz/Documents/Projects/wedge/venv38/lib/python3.8/site-packages/django/core/servers/basehttp.py", line 174 in handle
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/socketserver.py", line 720 in __init__
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/socketserver.py", line 360 in finish_request
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/socketserver.py", line 650 in process_request_thread
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/threading.py", line 870 in run
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/threading.py", line 932 in _bootstrap_inner
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/threading.py", line 890 in _bootstrap
One stood out to me as trying to reconfigure logging through wsgi.py:
Thread 0x000070000eed5000 (most recent call first):
File "<frozen importlib._bootstrap>", line 163 in _get_module_lock
File "<frozen importlib._bootstrap>", line 148 in __enter__
File "<frozen importlib._bootstrap>", line 988 in _find_and_load
File "<frozen importlib._bootstrap>", line 1014 in _gcd_import
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/importlib/__init__.py", line 127 in import_module
File "/Users/chainz/Documents/Projects/wedge/venv38/lib/python3.8/site-packages/django/utils/module_loading.py", line 17 in import_string
File "/Users/chainz/Documents/Projects/wedge/venv38/lib/python3.8/site-packages/django/utils/log.py", line 89 in __init__
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/logging/config.py", line 744 in configure_handler
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/logging/config.py", line 563 in configure
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/logging/config.py", line 808 in dictConfig
File "/Users/chainz/Documents/Projects/wedge/venv38/lib/python3.8/site-packages/django/utils/log.py", line 71 in configure_logging
File "/Users/chainz/Documents/Projects/wedge/venv38/lib/python3.8/site-packages/django/__init__.py", line 19 in setup
File "/Users/chainz/Documents/Projects/wedge/venv38/lib/python3.8/site-packages/django/core/wsgi.py", line 12 in get_wsgi_application
File "/Users/chainz/Documents/Projects/wedge/wedge/wsgi.py", line 6 in application
File "/Users/chainz/Documents/Projects/wedge/venv38/lib/python3.8/site-packages/django/contrib/staticfiles/handlers.py", line 68 in __call__
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/wsgiref/handlers.py", line 137 in run
File "/Users/chainz/Documents/Projects/wedge/venv38/lib/python3.8/site-packages/django/core/servers/basehttp.py", line 197 in handle_one_request
File "/Users/chainz/Documents/Projects/wedge/venv38/lib/python3.8/site-packages/django/core/servers/basehttp.py", line 174 in handle
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/socketserver.py", line 720 in __init__
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/socketserver.py", line 360 in finish_request
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/socketserver.py", line 650 in process_request_thread
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/threading.py", line 870 in run
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/threading.py", line 932 in _bootstrap_inner
File "/Users/chainz/.pyenv/versions/3.8.2/lib/python3.8/threading.py", line 890 in _bootstrap
This stood out to me. I checked your wsgi.py , it contained:
def application(environ, start_response):
return get_wsgi_application()(environ, start_response)
This means "create a new wsgi application for each request." During creation of a WSGI application, Django sets itself up, including configuring logging. This is why logging was trying to acquire that lock.
I changed it to use the standard definition from the startproject template:
application = get_wsgi_application()
(The outrer "def application" was previously a no-op, so gone)
Then I stopped experiencing the logging issue. This is your solution.
So it seems there *may* be a python logging lock issue if you reconfigure logging whilst logs are being sent in other threads. But I'm not sure if that is intended to be supported.