Skip to content

Commit 3dcdc2c

Browse files
glados-vermaarsharma1
authored andcommitted
Use default SIGINT handler if no tests are running. (google#897)
* Move signal.signal() registration from package __init__ to Test.execute * Revert "Move signal.signal() registration from package __init__ to Test.execute" This reverts commit 6f6729c. * Use default SIGINT handler if no tests are running.
1 parent 05b2a06 commit 3dcdc2c

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

openhtf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ def get_version():
5757
__version__ = get_version()
5858

5959
# Register signal handler to stop all tests on SIGINT.
60-
signal.signal(signal.SIGINT, Test.handle_sig_int)
60+
Test.DEFAULT_SIGINT_HANDLER = signal.signal(signal.SIGINT, Test.handle_sig_int)

openhtf/core/test_descriptor.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def PhaseTwo(test):
126126

127127
TEST_INSTANCES = weakref.WeakValueDictionary()
128128
HANDLED_SIGINT_ONCE = False
129+
DEFAULT_SIGINT_HANDLER = None
129130

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

230231
@classmethod
231-
def handle_sig_int(cls, *_):
232-
if cls.TEST_INSTANCES:
233-
_LOG.error('Received SIGINT, stopping all tests.')
234-
for test in cls.TEST_INSTANCES.values():
235-
test.abort_from_sig_int()
232+
def handle_sig_int(cls, signalnum, handler):
233+
if not cls.TEST_INSTANCES:
234+
cls.DEFAULT_SIGINT_HANDLER(signalnum, handler)
235+
return
236+
237+
_LOG.error('Received SIGINT, stopping all tests.')
238+
for test in cls.TEST_INSTANCES.values():
239+
test.abort_from_sig_int()
236240
if not cls.HANDLED_SIGINT_ONCE:
237241
cls.HANDLED_SIGINT_ONCE = True
238242
raise KeyboardInterrupt

0 commit comments

Comments
 (0)