浏览代码

Loader configuration (e.g. django.conf) should not be included when pickling an app

Ask Solem 14 年之前
父节点
当前提交
b9b35f32b6
共有 3 个文件被更改,包括 21 次插入18 次删除
  1. 14 12
      celery/app/base.py
  2. 5 4
      celery/datastructures.py
  3. 2 2
      celery/tests/test_datastructures.py

+ 14 - 12
celery/app/base.py

@@ -212,25 +212,25 @@ class BaseApp(object):
         defaults."""
         if not c.get("CELERY_QUEUES"):
             c["CELERY_QUEUES"] = {
-                c.CELERY_DEFAULT_QUEUE: {
-                    "exchange": c.CELERY_DEFAULT_EXCHANGE,
-                    "exchange_type": c.CELERY_DEFAULT_EXCHANGE_TYPE,
-                    "binding_key": c.CELERY_DEFAULT_ROUTING_KEY}}
+                c["CELERY_DEFAULT_QUEUE"]: {
+                    "exchange": c["CELERY_DEFAULT_EXCHANGE"],
+                    "exchange_type": c["CELERY_DEFAULT_EXCHANGE_TYPE"],
+                    "binding_key": c["CELERY_DEFAULT_ROUTING_KEY"]}}
         c["CELERY_ROUTES"] = routes.prepare(c.get("CELERY_ROUTES") or {})
         if c.get("CELERYD_LOG_COLOR") is None:
-            c["CELERYD_LOG_COLOR"] = not c.CELERYD_LOG_FILE and \
+            c["CELERYD_LOG_COLOR"] = not c["CELERYD_LOG_FILE"] and \
                                         isatty(sys.stderr)
         if self.IS_WINDOWS:  # windows console doesn't support ANSI colors
             c["CELERYD_LOG_COLOR"] = False
-        if isinstance(c.CELERY_TASK_RESULT_EXPIRES, int):
+        if isinstance(c["CELERY_TASK_RESULT_EXPIRES"], int):
             c["CELERY_TASK_RESULT_EXPIRES"] = timedelta(
-                    seconds=c.CELERY_TASK_RESULT_EXPIRES)
+                    seconds=c["CELERY_TASK_RESULT_EXPIRES"])
 
         # Install backend cleanup periodic task.
-        c.CELERYBEAT_SCHEDULE = maybe_promise(c.CELERYBEAT_SCHEDULE)
-        if c.CELERY_TASK_RESULT_EXPIRES:
+        c["CELERYBEAT_SCHEDULE"] = maybe_promise(c["CELERYBEAT_SCHEDULE"])
+        if c["CELERY_TASK_RESULT_EXPIRES"]:
             from celery.schedules import crontab
-            c.CELERYBEAT_SCHEDULE.setdefault("celery.backend_cleanup",
+            c["CELERYBEAT_SCHEDULE"].setdefault("celery.backend_cleanup",
                     dict(task="celery.backend_cleanup",
                          schedule=crontab(minute="00", hour="04",
                                           day_of_week="*"),
@@ -276,8 +276,10 @@ class BaseApp(object):
         return backend_cls(app=self)
 
     def _get_config(self):
-        return self.post_config_merge(ConfigurationView(
-                    self.pre_config_merge(self.loader.conf), DEFAULTS))
+        return self.post_config_merge(
+                        ConfigurationView({}, [
+                            self.pre_config_merge(self.loader.conf),
+                            DEFAULTS]))
 
     @cached_property
     def amqp(self):

+ 5 - 4
celery/datastructures.py

@@ -90,9 +90,10 @@ class ConfigurationView(AttributeDictMixin):
     def __init__(self, changes, defaults):
         self.__dict__["changes"] = changes
         self.__dict__["defaults"] = defaults
+        self.__dict__["_order"] = [changes] + defaults
 
     def __getitem__(self, key):
-        for d in self.__dict__["changes"], self.__dict__["defaults"]:
+        for d in self.__dict__["_order"]:
             try:
                 return d[key]
             except KeyError:
@@ -119,7 +120,7 @@ class ConfigurationView(AttributeDictMixin):
         return self.__dict__["changes"].update(*args, **kwargs)
 
     def __contains__(self, key):
-        for d in self.__dict__["changes"], self.__dict__["defaults"]:
+        for d in self.__dict__["_order"]:
             if key in d:
                 return True
         return False
@@ -130,8 +131,8 @@ class ConfigurationView(AttributeDictMixin):
     def __iter__(self):
         # defaults must be first in the stream, so values in
         # in changes takes precedence.
-        return chain(*[d.iteritems() for d in (self.__dict__["defaults"],
-                                               self.__dict__["changes"])])
+        return chain(*[d.iteritems()
+                        for d in reversed(self.__dict__["_order"])])
 
     def iteritems(self):
         return iter(self)

+ 2 - 2
celery/tests/test_datastructures.py

@@ -48,8 +48,8 @@ class test_ConfigurationView(unittest.TestCase):
     def setUp(self):
         self.view = ConfigurationView({"changed_key": 1,
                                        "both": 2},
-                                      {"default_key": 1,
-                                       "both": 1})
+                                      [{"default_key": 1,
+                                       "both": 1}])
 
     def test_setdefault(self):
         self.assertEqual(self.view.setdefault("both", 36), 2)