summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-01-12 22:04:22 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-01-12 22:08:46 +0100
commitd674fe6dee16735dd2670243153326806b7e6cb0 (patch)
tree4fe400c9bade0675f91c451e8ee8f17845d150cc
parent225a6ed2cfecc609760a36c3b20369daeec52e07 (diff)
Used a regular lock for app registry population.
Since the app registry is always populated before the first request is processed, the situation described in #18251 for the old app cache cannot happen any more. Refs #18251, #21628.
-rw-r--r--django/apps/registry.py13
-rw-r--r--django/utils/module_loading.py13
2 files changed, 8 insertions, 18 deletions
diff --git a/django/apps/registry.py b/django/apps/registry.py
index a0cd5e0abf..fcd5f576e6 100644
--- a/django/apps/registry.py
+++ b/django/apps/registry.py
@@ -1,11 +1,11 @@
from collections import Counter, defaultdict, OrderedDict
import os
import sys
+import threading
import warnings
from django.core.exceptions import ImproperlyConfigured
from django.utils import lru_cache
-from django.utils.module_loading import import_lock
from django.utils._os import upath
from .base import AppConfig
@@ -44,6 +44,9 @@ class Apps(object):
# Whether the registry is populated.
self.ready = False
+ # Lock for thread-safe population.
+ self._lock = threading.Lock()
+
# Pending lookups for lazy relations.
self._pending_lookups = {}
@@ -61,10 +64,10 @@ class Apps(object):
"""
if self.ready:
return
- # Since populate() may be a side effect of imports, and since it will
- # itself import modules, an ABBA deadlock between threads would be
- # possible if we didn't take the import lock. See #18251.
- with import_lock():
+
+ # populate() might be called by two threads in parallel on servers
+ # that create threads before initializing the WSGI callable.
+ with self._lock:
if self.ready:
return
diff --git a/django/utils/module_loading.py b/django/utils/module_loading.py
index bd012cd55b..a6fe7aebcb 100644
--- a/django/utils/module_loading.py
+++ b/django/utils/module_loading.py
@@ -1,6 +1,5 @@
from __future__ import absolute_import # Avoid importing `importlib` from this package.
-from contextlib import contextmanager
import copy
import imp
from importlib import import_module
@@ -36,18 +35,6 @@ def import_by_path(dotted_path, error_prefix=''):
return attr
-@contextmanager
-def import_lock():
- """
- Context manager that aquires the import lock.
- """
- imp.acquire_lock()
- try:
- yield
- finally:
- imp.release_lock()
-
-
def autodiscover_modules(*args, **kwargs):
"""
Auto-discover INSTALLED_APPS modules and fail silently when