4
from functools import wraps
9
class _InterruptHandler(object):
10
def __init__(self, default_handler):
12
self.default_handler = default_handler
14
def __call__(self, signum, frame):
15
installed_handler = signal.getsignal(signal.SIGINT)
16
if installed_handler is not self:
17
# if we aren't the installed handler, then delegate immediately
18
# to the default handler
19
self.default_handler(signum, frame)
22
self.default_handler(signum, frame)
24
for result in _results.keys():
27
_results = weakref.WeakKeyDictionary()
28
def registerResult(result):
31
def removeResult(result):
32
return bool(_results.pop(result, None))
34
_interrupt_handler = None
36
global _interrupt_handler
37
if _interrupt_handler is None:
38
default_handler = signal.getsignal(signal.SIGINT)
39
_interrupt_handler = _InterruptHandler(default_handler)
40
signal.signal(signal.SIGINT, _interrupt_handler)
43
def removeHandler(method=None):
44
if method is not None:
46
def inner(*args, **kwargs):
47
initial = signal.getsignal(signal.SIGINT)
50
return method(*args, **kwargs)
52
signal.signal(signal.SIGINT, initial)
55
global _interrupt_handler
56
if _interrupt_handler is not None:
57
signal.signal(signal.SIGINT, _interrupt_handler.default_handler)