title: deadlock detected when trying to start server
body: <p>I have a simple application where I am using both django and django-rest-framework.</p>
  
  <p>Quite often, when I try to start the local server (<code>python manage.py runserver</code>), I get the following exception:</p>
  
  <pre><code>Watching for file changes with StatReloader
  Exception in thread Thread-1:
  Traceback (most recent call last):
    File "/project/venv/lib/python3.7/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/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 917, in _bootstrap_inner
      self.run()
    File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 865, in run
      self._target(*self._args, **self._kwargs)
    File "/project/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
      fn(*args, **kwargs)
    File "/project/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
      self.check(display_num_errors=True)
    File "/project/venv/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check
      include_deployment_checks=include_deployment_checks,
    File "/project/venv/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks
      return checks.run_checks(**kwargs)
    File "/project/venv/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
      new_errors = check(app_configs=app_configs)
    File "/project/venv/lib/python3.7/site-packages/django/contrib/admin/checks.py", line 80, in check_dependencies
      for engine in engines.all():
    File "/project/venv/lib/python3.7/site-packages/django/template/utils.py", line 90, in all
      return [self[alias] for alias in self]
    File "/project/venv/lib/python3.7/site-packages/django/template/utils.py", line 90, in &lt;listcomp&gt;
      return [self[alias] for alias in self]
    File "/project/venv/lib/python3.7/site-packages/django/template/utils.py", line 81, in __getitem__
      engine = engine_cls(params)
    File "/project/venv/lib/python3.7/site-packages/django/template/backends/django.py", line 25, in __init__
      options['libraries'] = self.get_templatetag_libraries(libraries)
    File "/project/venv/lib/python3.7/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
      libraries = get_installed_libraries()
    File "/project/venv/lib/python3.7/site-packages/django/template/backends/django.py", line 108, in get_installed_libraries
      for name in get_package_libraries(pkg):
    File "/project/venv/lib/python3.7/site-packages/django/template/backends/django.py", line 121, in get_package_libraries
      module = import_module(entry[1])
    File "/project/venv/lib/python3.7/importlib/__init__.py", line 127, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File "&lt;frozen importlib._bootstrap&gt;", line 1006, in _gcd_import
    File "&lt;frozen importlib._bootstrap&gt;", line 983, in _find_and_load
    File "&lt;frozen importlib._bootstrap&gt;", line 967, in _find_and_load_unlocked
    File "&lt;frozen importlib._bootstrap&gt;", line 677, in _load_unlocked
    File "&lt;frozen importlib._bootstrap_external&gt;", line 728, in exec_module
    File "&lt;frozen importlib._bootstrap&gt;", line 219, in _call_with_frames_removed
    File "/project/venv/lib/python3.7/site-packages/rest_framework/templatetags/rest_framework.py", line 15, in &lt;module&gt;
      from rest_framework.renderers import HTMLFormRenderer
    File "/project/venv/lib/python3.7/site-packages/rest_framework/renderers.py", line 20, in &lt;module&gt;
      from django.test.client import encode_multipart
    File "/project/venv/lib/python3.7/site-packages/django/test/client.py", line 23, in &lt;module&gt;
      from django.test import signals
    File "&lt;frozen importlib._bootstrap&gt;", line 980, in _find_and_load
    File "&lt;frozen importlib._bootstrap&gt;", line 149, in __enter__
    File "&lt;frozen importlib._bootstrap&gt;", line 94, in acquire
  _frozen_importlib._DeadlockError: deadlock detected by _ModuleLock('django.test.signals') at 4420467792
  
  Performing system checks...
  </code></pre>
  
  <p>After a couple of retries, the server starts successfully. Therefore, it is not a show-stopper but it is quite annoying.</p>
  
  <p>Since I am quite new to Django, I was wondering if there was a way to prevent such an error.</p>