localpdb/utils/os.py
def clean_exit(callback=None, append=False):
    """A context manager which properly handles SIGTERM and SIGINT
    Modified version of the handle_exit function
    Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
    License: MIT
    """
    killed = False
    old_handler = signal.signal(signal.SIGTERM, _sigterm_handler)
    if (old_handler != signal.SIG_DFL) and (old_handler != _sigterm_handler):
        if not append:
            raise RuntimeError("there is already a handler registered for "
                               "SIGTERM: %r" % old_handler)

        def handler(signum, frame):
            try:
                _sigterm_handler(signum, frame)
            finally:
                old_handler(signum, frame)
                killed = True

        signal.signal(signal.SIGTERM, handler)

    if _sigterm_handler.__enter_ctx__:
        raise RuntimeError("can't use nested contexts")
    _sigterm_handler.__enter_ctx__ = True

    try:
        yield
    except KeyboardInterrupt:
        killed = True
        sys.exit(1)
    except SystemExit as err:
        # code != 0 refers to an application error (e.g. explicit
        # sys.exit('some error') call).
        # We don't want that to pass silently.
        # Nevertheless, the 'finally' clause below will always
        # be executed.
        killed = True
        if err.code != 0:
            raise
    finally:
        _sigterm_handler.__enter_ctx__ = False
        if callback is not None and killed:
            logger.error('Script abruptly terminated! Cleaning temporary files...')
            callback()
            sys.exit(1)
A context manager which properly handles SIGTERM and SIGINT
    Modified version of the handle_exit function
    Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
    License: MIT
    
A context manager which properly handles SIGTERM and SIGINT
Modified version of the handle_exit function
Giampaolo Rodola' 
License: MIT
A context manager which properly handles SIGTERM and SIGINT Modified version of the handle_exit function Giampaolo Rodola ' License : MIT
def clean_exit(callback=None, append=False):
    killed = False
    old_handler = signal.signal(signal.SIGTERM, _sigterm_handler)
    if (old_handler != signal.SIG_DFL) and (old_handler != _sigterm_handler):
        if not append:
            raise RuntimeError("there is already a handler registered for "
                               "SIGTERM: %r" % old_handler)
        def handler(signum, frame):
            try:
                _sigterm_handler(signum, frame)
            finally:
                old_handler(signum, frame)
                killed = True
        signal.signal(signal.SIGTERM, handler)
    if _sigterm_handler.__enter_ctx__:
        raise RuntimeError("can't use nested contexts")
    _sigterm_handler.__enter_ctx__ = True
    try:
        yield
    except KeyboardInterrupt:
        killed = True
        sys.exit(1)
    except SystemExit as err:
        killed = True
        if err.code != 0:
            raise
    finally:
        _sigterm_handler.__enter_ctx__ = False
        if callback is not None and killed:
            logger.error('Script abruptly terminated! Cleaning temporary files...')
            callback()
            sys.exit(1)
def clean_exit ( callback = None , append = False ) : killed = False old_handler = signal . signal ( signal . SIGTERM , _sigterm_handler ) if ( old_handler != signal . SIG_DFL ) and ( old_handler != _sigterm_handler ) : if not append : raise RuntimeError ( "there is already a handler registered for " "SIGTERM: %r" % old_handler ) def handler ( signum , frame ) : try : _sigterm_handler ( signum , frame ) finally : old_handler ( signum , frame ) killed = True signal . signal ( signal . SIGTERM , handler ) if _sigterm_handler . __enter_ctx__ : raise RuntimeError ( "can't use nested contexts" ) _sigterm_handler . __enter_ctx__ = True try : yield except KeyboardInterrupt : killed = True sys . exit ( 1 ) except SystemExit as err : killed = True if err . code != 0 : raise finally : _sigterm_handler . __enter_ctx__ = False if callback is not None and killed : logger . error ( 'Script abruptly terminated! Cleaning temporary files...' ) callback ( ) sys . exit ( 1 )
A context manager which properly handles SIGTERM and SIGINT
Modified version of the handle_exit function
Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
License: MIT
A context manager which properly handles SIGTERM and SIGINT Modified version of the handle_exit function Giampaolo Rodola ' <g . rodola [ AT ] gmail [ DOT ] com > License : MIT
"""A context manager which properly handles SIGTERM and SIGINT
    Modified version of the handle_exit function
    Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
    License: MIT
    """ # code != 0 refers to an application error (e.g. explicit # sys.exit('some error') call). # We don't want that to pass silently. # Nevertheless, the 'finally' clause below will always # be executed.
callback
append