A lot many times I encounter this error while starting python server. This also happens when I change any file and server boots up again.
I've tried deleting the environment and re-creating the environment but still the same error persists.
Python 3.5.2 (default, Nov 12 2018, 13:43:14) [GCC 5.4.0 20160609] on linux
Django: 2.2.1
/home/satyam/Code/myproject/myproject_apps/invoice/services/excel_service.py changed, reloading.
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/template/utils.py", line 66, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/contrib/admin/checks.py", line 79, in check_dependencies
for engine in engines.all():
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/template/utils.py", line 90, in all
return [self[alias] for alias in self]
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/template/utils.py", line 90, in <listcomp>
return [self[alias] for alias in self]
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/template/utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/template/backends/django.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/template/backends/django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/template/backends/django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "/home/satyam/Code/environments/ebapps/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/rest_framework/templatetags/rest_framework.py", line 15, in <module>
from rest_framework.renderers import HTMLFormRenderer
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/rest_framework/renderers.py", line 20, in <module>
from django.test.client import encode_multipart
File "/home/satyam/Code/environments/ebapps/lib/python3.5/site-packages/django/test/client.py", line 23, in <module>
from django.test import signals
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 168, in __enter__
File "<frozen importlib._bootstrap>", line 110, in acquire
_frozen_importlib._DeadlockError: deadlock detected by _ModuleLock('django.test.signals') at 140078699689688
What was causing the error for me was this import:
from rest_framework.urlpatterns import format_suffix_patterns
removing it solved immediately the issue.
Looks like you have deadlocks because sending signal from signal handler to the same model. Or second handler wait for some resource to be unlocked from first. Most probably row or table is locked on database level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With