def install_HUP_not_supported_handler(worker): def warn_on_HUP_handler(signum, frame): worker.logger.error( "SIGHUP not supported: " "Restarting with HUP is unstable on this platform!") platforms.install_signal_handler(SIGHUP=warn_on_HUP_handler)
def install_HUP_not_supported_handler(worker): def warn_on_HUP_handler(signum, frame): worker.logger.error("SIGHUP not supported: " "Restarting with HUP is unstable on this platform!") platforms.install_signal_handler("SIGHUP", warn_on_HUP_handler)
def install_worker_restart_handler(worker): def restart_worker_sig_handler(signum, frame): """Signal handler restarting the current python program.""" worker.logger.warn("Restarting celeryd (%s)" % (" ".join(sys.argv))) worker.stop(in_sighandler=True) os.execv(sys.executable, [sys.executable] + sys.argv) platforms.install_signal_handler(SIGHUP=restart_worker_sig_handler)
def install_worker_restart_handler(worker): def restart_worker_sig_handler(signum, frame): """Signal handler restarting the current python program.""" worker.logger.warn("Restarting celeryd (%s)" % (" ".join(sys.argv))) worker.stop(in_sighandler=True) os.execv(sys.executable, [sys.executable] + sys.argv) platforms.install_signal_handler("SIGHUP", restart_worker_sig_handler)
def install_rdb_handler(): # pragma: no cover def rdb_handler(signum, frame): """Signal handler setting a rdb breakpoint at the current frame.""" from celery.contrib import rdb rdb.set_trace(frame) if os.environ.get("CELERY_RDBSIG"): platforms.install_signal_handler(SIGUSR2=rdb_handler)
def install_worker_term_handler(worker): def _stop(signum, frame): process_name = multiprocessing.current_process().name if process_name == "MainProcess": worker.logger.warn("celeryd: Warm shutdown (%s)" % (process_name)) worker.stop() raise SystemExit() platforms.install_signal_handler("SIGTERM", _stop)
def install_sync_handler(self, beat): """Install a `SIGTERM` + `SIGINT` handler that saves the celerybeat schedule.""" def _sync(signum, frame): beat.sync() raise SystemExit() platforms.install_signal_handler(SIGTERM=_sync, SIGINT=_sync)
def install_cry_handler(logger): # 2.4 does not have sys._current_frames if sys.version_info > (2, 5): def cry_handler(signum, frame): """Signal handler logging the stacktrace of all active threads.""" logger.error("\n" + cry()) platforms.install_signal_handler("SIGUSR1", cry_handler)
def install_worker_int_again_handler(worker): def _stop(signum, frame): process_name = multiprocessing.current_process().name if process_name == "MainProcess": worker.logger.warn("celeryd: Cold shutdown (%s)" % (process_name)) worker.terminate() raise SystemExit() platforms.install_signal_handler("SIGINT", _stop)
def install_worker_term_handler(worker): def _stop(signum, frame): process_name = multiprocessing.current_process().name if process_name == "MainProcess": worker.logger.warn("celeryd: Warm shutdown (%s)" % ( process_name)) worker.stop(in_sighandler=True) raise SystemExit() platforms.install_signal_handler("SIGTERM", _stop)
def install_worker_int_again_handler(worker): def _stop(signum, frame): process_name = multiprocessing.current_process().name if process_name == "MainProcess": worker.logger.warn("celeryd: Cold shutdown (%s)" % ( process_name)) worker.terminate(in_sighandler=True) raise SystemTerminate() platforms.install_signal_handler("SIGINT", _stop)
def install_cry_handler(logger): # 2.4 does not have sys._current_frames is_jython = sys.platform.startswith("java") is_pypy = hasattr(sys, "pypy_version_info") if not (is_jython or is_pypy) and sys.version_info > (2, 5): def cry_handler(signum, frame): """Signal handler logging the stacktrace of all active threads.""" logger.error("\n" + cry()) platforms.install_signal_handler(SIGUSR1=cry_handler)
def install_worker_int_again_handler(worker): def _stop(signum, frame): process_name = None if multiprocessing: process_name = multiprocessing.current_process().name if not process_name or process_name == "MainProcess": worker.logger.warn("celeryd: Cold shutdown (%s)" % (process_name)) worker.terminate(in_sighandler=True) raise SystemTerminate() platforms.install_signal_handler(SIGINT=_stop)
def install_worker_int_handler(worker): def _stop(signum, frame): process_name = multiprocessing.current_process().name if process_name == "MainProcess": worker.logger.warn("celeryd: Hitting Ctrl+C again will terminate " "all running tasks!") install_worker_int_again_handler(worker) worker.logger.warn("celeryd: Warm shutdown (%s)" % (process_name)) worker.stop() raise SystemExit() platforms.install_signal_handler("SIGINT", _stop)
def install_worker_int_handler(worker): def _stop(signum, frame): process_name = None if multiprocessing: process_name = multiprocessing.current_process().name if not process_name or process_name == "MainProcess": worker.logger.warn("celeryd: Hitting Ctrl+C again will terminate " "all running tasks!") install_worker_int_again_handler(worker) worker.logger.warn("celeryd: Warm shutdown (%s)" % (process_name)) worker.stop(in_sighandler=True) raise SystemExit() platforms.install_signal_handler("SIGINT", _stop)