Example #1
0
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)
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
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)
Example #6
0
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)
Example #7
0
    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)
Example #8
0
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)
Example #9
0
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)
Example #10
0
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)
Example #11
0
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)
Example #12
0
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)
Example #13
0
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)
Example #14
0
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)
Example #15
0
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)
Example #16
0
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)
Example #17
0
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)