def _turn_sigterm_into_systemexit ( ) : # pragma: no cover try : import signal except ImportError : return def handle_term ( signo , frame ) : raise SystemExit signal . signal ( signal . SIGTERM , handle_term )
how to add keyboardinterrupt signal handler in python
Attempts to turn a SIGTERM exception into a SystemExit exception .
def _turn_sigterm_into_systemexit(): # pragma: no cover
    """
    Attempts to turn a SIGTERM exception into a SystemExit exception.
    """
    try:
        import signal
    except ImportError:
        return
    def handle_term(signo, frame):
        raise SystemExit
    signal.signal(signal.SIGTERM, handle_term)