def exit_handler(signum, frame):
    """
    Catch SIGTERM and SIGHUP and call "sys.exit" which raises
    "SystemExit" exception.
    This will trigger all the cleanup code defined in ContextManagers
    and "finally" statements.

    For more details about the arguments see "signal" documentation.

    Args:
        signum(int): The signal's number
        frame(frame): The current stack frame, can be None
    """

    LOGGER.debug('signal {} was caught'.format(signum))
    sys.exit(128 + signum)
Catch SIGTERM and SIGHUP and call "sys.exit" which raises
    "SystemExit" exception.
    This will trigger all the cleanup code defined in ContextManagers
    and "finally" statements.

    For more details about the arguments see "signal" documentation.

    Args:
        signum(int): The signal's number
        frame(frame): The current stack frame, can be None