Skip to content

Commit d87c21c

Browse files
committed
Warn if thread/socket depended celery modules loaded before eventlet patched
1 parent 8e11d7b commit d87c21c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

celery/concurrency/eventlet.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@
1010

1111
import os
1212

13-
EVENTLET_NOPATCH = int(os.environ.get('EVENTLET_NOPATCH', 0))
13+
EVENTLET_NOPATCH = os.environ.get('EVENTLET_NOPATCH', False)
1414
EVENTLET_DBLOCK = int(os.environ.get('EVENTLET_NOBLOCK', 0))
15+
W_RACE = """\
16+
Celery module with %s imported before eventlet patched\
17+
"""
18+
19+
def _racedetect():
20+
import sys
21+
for mod in (mod for mod in sys.modules if mod.startswith('celery.')):
22+
for side in ('thread', 'threading', 'socket'):
23+
if getattr(mod, side, None):
24+
warnings.warn(RuntimeWarning(W_RACE % side))
25+
_racedetect()
26+
1527

1628
PATCHED = [0]
1729
if not EVENTLET_NOPATCH and not PATCHED[0]:

0 commit comments

Comments
 (0)