MCPcopy Create free account
hub / github.com/celery/celery / Hub

Class Hub

celery/worker/components.py:56–98  ·  view source on GitHub ↗

Worker starts the event loop.

Source from the content-addressed store, hash-verified

54
55
56class Hub(bootsteps.StartStopStep):
57 """Worker starts the event loop."""
58
59 requires = (Timer,)
60
61 def __init__(self, w, **kwargs):
62 w.hub = None
63 super().__init__(w, **kwargs)
64
65 def include_if(self, w):
66 return w.use_eventloop
67
68 def create(self, w):
69 w.hub = get_event_loop()
70 if w.hub is None:
71 required_hub = getattr(w._conninfo, 'requires_hub', None)
72 w.hub = set_event_loop((
73 required_hub if required_hub else _Hub)(w.timer))
74 self._patch_thread_primitives(w)
75 return self
76
77 def start(self, w):
78 # Ensure the kombu hub's poller is initialized before the event loop starts.
79 # Since asynloop() no longer resets the hub on exit (to preserve timers
80 # during shutdown), we must initialize the poller upfront.
81 _ = w.hub.poller
82
83 def stop(self, w):
84 w.hub.close()
85
86 def terminate(self, w):
87 w.hub.close()
88
89 def _patch_thread_primitives(self, w):
90 # make clock use dummy lock
91 w.app.clock.mutex = DummyLock()
92 # multiprocessing's ApplyResult uses this lock.
93 try:
94 from billiard import pool
95 except ImportError:
96 pass
97 else:
98 pool.Lock = DummyLock
99
100
101class Pool(bootsteps.StartStopStep):

Calls

no outgoing calls