mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Closes issue 15505. unittest.installHandler and non-callable signal handlers.
This commit is contained in:
parent
45c4375ea7
commit
6debd76939
3 changed files with 50 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue