Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openhtf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ def get_version():
__version__ = get_version()

# Register signal handler to stop all tests on SIGINT.
signal.signal(signal.SIGINT, Test.handle_sig_int)
Test.DEFAULT_SIGINT_HANDLER = signal.signal(signal.SIGINT, Test.handle_sig_int)
14 changes: 9 additions & 5 deletions openhtf/core/test_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def PhaseTwo(test):

TEST_INSTANCES = weakref.WeakValueDictionary()
HANDLED_SIGINT_ONCE = False
DEFAULT_SIGINT_HANDLER = None

def __init__(self, *phases, **metadata):
# Some sanity checks on special metadata keys we automatically fill in.
Expand Down Expand Up @@ -228,11 +229,14 @@ def configure(self, **kwargs):
setattr(self._test_options, key, value)

@classmethod
def handle_sig_int(cls, *_):
if cls.TEST_INSTANCES:
_LOG.error('Received SIGINT, stopping all tests.')
for test in cls.TEST_INSTANCES.values():
test.abort_from_sig_int()
def handle_sig_int(cls, signalnum, handler):
if not cls.TEST_INSTANCES:
cls.DEFAULT_SIGINT_HANDLER(signalnum, handler)
return

_LOG.error('Received SIGINT, stopping all tests.')
for test in cls.TEST_INSTANCES.values():
test.abort_from_sig_int()
if not cls.HANDLED_SIGINT_ONCE:
cls.HANDLED_SIGINT_ONCE = True
raise KeyboardInterrupt
Expand Down