def handle_sigterm():
    """Handle SIGTERM like a normal SIGINT (KeyboardInterrupt).

    By default Docker sends a SIGTERM for stopping containers, giving them
    time to terminate before getting killed. If a process does not catch this
    signal and does nothing, it just gets killed.

    Handling SIGTERM like SIGINT allows to gracefully terminate both
    interactively with ^C and with `docker stop`.

    This context manager restores the default SIGTERM behavior when exiting.
    """
    original_sigterm_handler = signal.getsignal(signal.SIGTERM)
    signal.signal(signal.SIGTERM, signal.default_int_handler)
    try:
        yield
    finally:
        signal.signal(signal.SIGTERM, original_sigterm_handler)
def handle_sigterm ( ) : original_sigterm_handler = signal . getsignal ( signal . SIGTERM ) signal . signal ( signal . SIGTERM , signal . default_int_handler ) try : yield finally : signal . signal ( signal . SIGTERM , original_sigterm_handler )
Handle SIGTERM like a normal SIGINT (KeyboardInterrupt).

    By default Docker sends a SIGTERM for stopping containers, giving them
    time to terminate before getting killed. If a process does not catch this
    signal and does nothing, it just gets killed.

    Handling SIGTERM like SIGINT allows to gracefully terminate both
    interactively with ^C and with `docker stop`.

    This context manager restores the default SIGTERM behavior when exiting.