Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion voom/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import threading

__version__ = "1.2.0"
__version__ = "1.3.0"
31 changes: 17 additions & 14 deletions voom/adaptors/django/discover.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
from logging import getLogger
import imp
import importlib
from logging import getLogger
import threading


LOG = getLogger(__name__)

_RACE_PROTECTION = False # protect against shenanigans.
_HANDLERS_LOADED = False # protect against shenanigans.


def autodiscover_bus_handlers():
"""Include handlers for all applications in ``INSTALLED_APPS``."""
from django.conf import settings
#from django.conf import settings
global _RACE_PROTECTION

if _RACE_PROTECTION:
return
_RACE_PROTECTION = True
try:
LOG.info("Discovering bus handlers...")
return filter(None, [find_related_module(app, "handlers")
for app in settings.INSTALLED_APPS])
finally:
_RACE_PROTECTION = False
# from django.conf import settings
global _HANDLERS_LOADED

with threading.RLock():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do a check before entering the lock. Then check once inside the lock.

if _HANDLERS_LOADED:
return
_HANDLERS_LOADED = True
try:
LOG.info("Discovering bus handlers...")
return filter(None, [find_related_module(app, "handlers")
for app in settings.INSTALLED_APPS])
finally:
_HANDLERS_LOADED = False


def find_related_module(app, related_name):
Expand Down