@contextlib.contextmanager
def signal_receiver(signums):
 signals = []
 prev_handlers = {}
 prev_handlers = get_signals(signums)
 set_signals(dict(((s, (lambda s, _: signals.append(s))) for s in signums)))
 (yield signals)
 set_signals(prev_handlers)

@ contextlib . contextmanager def signal_receiver ( signums ) : signals = [ ] prev_handlers = { } prev_handlers = get_signals ( signums ) set_signals ( dict ( ( ( s , ( lambda s , _ : signals . append ( s ) ) ) for s in signums ) ) ) ( yield signals ) set_signals ( prev_handlers )
context manager to catch signals .