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

Function _handle_request

celery/apps/worker.py:337–361  ·  view source on GitHub ↗
(*args)

Source from the content-addressed store, hash-verified

335 verbose (bool, optional): Whether to print the type of shutdown. Defaults to True.
336 """
337 def _handle_request(*args):
338 with in_sighandler():
339 from celery.worker import state
340 try:
341 if current_process()._name == 'MainProcess':
342 if callback:
343 callback(worker)
344 if verbose:
345 safe_say(f'worker: {how} shutdown (MainProcess)', sys.__stdout__)
346 signals.worker_shutting_down.send(
347 sender=worker.hostname, sig=sig, how=how,
348 exitcode=exitcode,
349 )
350 finally:
351 # Guarantee the shutdown flag is set even if the callback,
352 # safe_say(), or the signal dispatch above raises — this is
353 # the actual mechanism that stops the worker from accepting
354 # new work. Kept in the *finally*, not moved ahead of this
355 # block, because on_cold_shutdown() relies on should_terminate
356 # staying unset while it runs: it waits out
357 # worker_soft_shutdown_timeout before cancelling tasks, and
358 # state.maybe_shutdown()/Request.on_timeout()/on_failure()
359 # all branch on should_terminate during that window.
360 setattr(state, {'Warm': 'should_stop',
361 'Cold': 'should_terminate'}[how], exitcode)
362 _handle_request.__name__ = str(f'worker_{how}')
363 platforms.signals[sig] = _handle_request
364

Callers

nothing calls this directly

Calls 5

in_sighandlerFunction · 0.90
current_processFunction · 0.85
callbackFunction · 0.85
safe_sayFunction · 0.85
sendMethod · 0.45

Tested by

no test coverage detected