瀏覽代碼

Django: Child processes must call django.setup if on Windows (Issue #2126)

Ask Solem 10 年之前
父節點
當前提交
ba7f500f6b
共有 1 個文件被更改,包括 9 次插入1 次删除
  1. 9 1
      celery/fixups/django.py

+ 9 - 1
celery/fixups/django.py

@@ -136,9 +136,11 @@ class DjangoWorkerFixup(object):
     def validate_models(self):
         import django
         try:
-            django.setup()
+            django_setup = django.setup
         except AttributeError:
             pass
+        else:
+            django_setup()
         s = io.StringIO()
         try:
             from django.core.management.validation import get_validation_errors
@@ -166,6 +168,12 @@ class DjangoWorkerFixup(object):
         return self
 
     def on_worker_process_init(self, **kwargs):
+        # Child process must validate models again if on Windows,
+        # or if they were started using execv.
+        if os.environ.get('FORKED_BY_MULTIPROCESSING'):
+            self.validate_models()
+
+        # close connections:
         # the parent process may have established these,
         # so need to close them.