diff options
author | Michael Foord <michael@voidspace.org.uk> | 2013-01-29 23:07:57 (GMT) |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2013-01-29 23:07:57 (GMT) |
commit | 6debd769393c9c5cdd4feb2a0c74bda173a13b1e (patch) | |
tree | fe028d9d93b7da53295cb24357abfe192060baff /Lib/unittest/signals.py | |
parent | 45c4375ea7da4a78e9d5dc7b79f98b7882cc7640 (diff) | |
download | cpython-6debd769393c9c5cdd4feb2a0c74bda173a13b1e.zip cpython-6debd769393c9c5cdd4feb2a0c74bda173a13b1e.tar.gz cpython-6debd769393c9c5cdd4feb2a0c74bda173a13b1e.tar.bz2 |
Closes issue 15505. unittest.installHandler and non-callable signal handlers.
Diffstat (limited to 'Lib/unittest/signals.py')
-rw-r--r-- | Lib/unittest/signals.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Lib/unittest/signals.py b/Lib/unittest/signals.py index fc31043..e6a5fc5 100644 --- a/Lib/unittest/signals.py +++ b/Lib/unittest/signals.py @@ -9,6 +9,20 @@ __unittest = True class _InterruptHandler(object): def __init__(self, default_handler): self.called = False + self.original_handler = default_handler + if isinstance(default_handler, int): + if default_handler == signal.SIG_DFL: + # Pretend it's signal.default_int_handler instead. + default_handler = signal.default_int_handler + elif default_handler == signal.SIG_IGN: + # Not quite the same thing as SIG_IGN, but the closest we + # can make it: do nothing. + def default_handler(unused_signum, unused_frame): + pass + else: + raise TypeError("expected SIGINT signal handler to be " + "signal.SIG_IGN, signal.SIG_DFL, or a " + "callable object") self.default_handler = default_handler def __call__(self, signum, frame): @@ -54,4 +68,4 @@ def removeHandler(method=None): global _interrupt_handler if _interrupt_handler is not None: - signal.signal(signal.SIGINT, _interrupt_handler.default_handler) + signal.signal(signal.SIGINT, _interrupt_handler.original_handler) |