Explorar o código

Warn if thread/socket depended celery modules loaded before eventlet patched

Ask Solem %!s(int64=12) %!d(string=hai) anos
pai
achega
d87c21cc79
Modificáronse 1 ficheiros con 13 adicións e 1 borrados
  1. 13 1
      celery/concurrency/eventlet.py

+ 13 - 1
celery/concurrency/eventlet.py

@@ -10,8 +10,20 @@ from __future__ import absolute_import
 
 import os
 
-EVENTLET_NOPATCH = int(os.environ.get('EVENTLET_NOPATCH', 0))
+EVENTLET_NOPATCH = os.environ.get('EVENTLET_NOPATCH', False)
 EVENTLET_DBLOCK = int(os.environ.get('EVENTLET_NOBLOCK', 0))
+W_RACE = """\
+Celery module with %s imported before eventlet patched\
+"""
+
+def _racedetect():
+    import sys
+    for mod in (mod for mod in sys.modules if mod.startswith('celery.')):
+            for side in ('thread', 'threading', 'socket'):
+                if getattr(mod, side, None):
+                    warnings.warn(RuntimeWarning(W_RACE % side))
+_racedetect()
+
 
 PATCHED = [0]
 if not EVENTLET_NOPATCH and not PATCHED[0]: