Skip to content

Commit 470be26

Browse files
committed
Can only check Pool.did_start_ok at startup. Closes celery#1118
1 parent 1a4e3e2 commit 470be26

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

celery/worker/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __init__(self, w,
9696
w.max_concurrency, w.min_concurrency = w.autoscale
9797
self.autoreload_enabled = autoreload
9898

99-
def on_poll_init(self, pool, hub):
99+
def on_poll_init(self, pool, w, hub):
100100
apply_after = hub.timer.apply_after
101101
apply_at = hub.timer.apply_at
102102
on_soft_timeout = pool.on_soft_timeout
@@ -106,7 +106,10 @@ def on_poll_init(self, pool, hub):
106106
remove = hub.remove
107107
now = time.time
108108

109-
if not pool.did_start_ok():
109+
# did_start_ok will verify that pool processes were able to start,
110+
# but this will only work the first time we start, as
111+
# maxtasksperchild will mess up metrics.
112+
if not w.consumer.restart_count and not pool.did_start_ok():
110113
raise WorkerLostError('Could not start worker processes')
111114

112115
# need to handle pool results before every task
@@ -167,7 +170,7 @@ def create(self, w, semaphore=None, max_restarts=None):
167170
semaphore=semaphore,
168171
)
169172
if w.hub:
170-
w.hub.on_init.append(partial(self.on_poll_init, pool))
173+
w.hub.on_init.append(partial(self.on_poll_init, pool, w))
171174
return pool
172175

173176

celery/worker/consumer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ class Consumer(object):
315315
# Consumer state, can be RUN or CLOSE.
316316
_state = None
317317

318+
restart_count = -1 # first start is the same as a restart
319+
318320
def __init__(self, ready_queue,
319321
init_callback=noop, send_events=False, hostname=None,
320322
initial_prefetch_count=2, pool=None, app=None,
@@ -384,6 +386,7 @@ def start(self):
384386
self.init_callback(self)
385387

386388
while self._state != CLOSE:
389+
self.restart_count += 1
387390
self.maybe_shutdown()
388391
try:
389392
self.reset_connection()

0 commit comments

Comments
 (0)