瀏覽代碼

eventlet: Also warn if billiard/kombu imported before patch

Ask Solem 13 年之前
父節點
當前提交
7420ee9766
共有 1 個文件被更改,包括 10 次插入7 次删除
  1. 10 7
      celery/concurrency/eventlet.py

+ 10 - 7
celery/concurrency/eventlet.py

@@ -9,20 +9,23 @@
 from __future__ import absolute_import
 
 import os
+import sys
 
 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\
 """
+RACE_MODS = ('billiard.', 'celery.', 'kombu.')
 
-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()
+
+#: Warn if we couldn't patch early enough,
+#: and thread/socket depending celery modules have already been loaded.
+for mod in (mod for mod in sys.modules if mod.startswith(RACE_MODS)):
+    for side in ('thread', 'threading', 'socket'):
+        if getattr(mod, side, None):
+            import warnings
+            warnings.warn(RuntimeWarning(W_RACE % side))
 
 
 PATCHED = [0]