浏览代码

celery.events.EventDispatcher: Don't create amqp channel if events disabled

Ask Solem 15 年之前
父节点
当前提交
d9ef3fae36
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      celery/events.py

+ 4 - 1
celery/events.py

@@ -38,11 +38,14 @@ class EventDispatcher(object):
     def __init__(self, connection, hostname=None, enabled=True,
     def __init__(self, connection, hostname=None, enabled=True,
             publisher=None):
             publisher=None):
         self.connection = connection
         self.connection = connection
-        self.publisher = publisher or EventPublisher(self.connection)
         self.hostname = hostname or socket.gethostname()
         self.hostname = hostname or socket.gethostname()
         self.enabled = enabled
         self.enabled = enabled
         self._lock = threading.Lock()
         self._lock = threading.Lock()
 
 
+        self.publisher = None
+        if self.enabled:
+            self.publisher = publisher or EventPublisher(self.connection)
+
     def send(self, type, **fields):
     def send(self, type, **fields):
         """Send event.
         """Send event.