Skip to content

Commit 87168f8

Browse files
committed
restore original signal handler for SIGALRM rather than just setting it to the default handler
1 parent c7e1c9a commit 87168f8

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

test/framework/run.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ def test_run_cmd_negative_exit_code(self):
206206
def handler(signum, _):
207207
raise RuntimeError("Signal handler called with signal %s" % signum)
208208

209+
orig_sigalrm_handler = signal.getsignal(signal.SIGALRM)
210+
209211
try:
210212
# set the signal handler and a 3-second alarm
211213
signal.signal(signal.SIGALRM, handler)
@@ -223,7 +225,7 @@ def handler(signum, _):
223225

224226
finally:
225227
# cleanup: disable the alarm + reset signal handler for SIGALRM
226-
signal.signal(signal.SIGALRM, signal.SIG_DFL)
228+
signal.signal(signal.SIGALRM, orig_sigalrm_handler)
227229
signal.alarm(0)
228230

229231
def test_run_cmd_bis(self):

test/framework/toy_build.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,6 +2744,8 @@ def test_toy_build_lock(self):
27442744
# also test use of --ignore-locks
27452745
self.test_toy_build(extra_args=extra_args + ['--ignore-locks'], verify=True, raise_error=True)
27462746

2747+
orig_sigalrm_handler = signal.getsignal(signal.SIGALRM)
2748+
27472749
# define a context manager that remove a lock after a while, so we can check the use of --wait-for-lock
27482750
class remove_lock_after(object):
27492751
def __init__(self, seconds, lock_fp):
@@ -2759,7 +2761,7 @@ def __enter__(self):
27592761

27602762
def __exit__(self, type, value, traceback):
27612763
# clean up SIGALRM signal handler, and cancel scheduled alarm
2762-
signal.signal(signal.SIGALRM, signal.SIG_DFL)
2764+
signal.signal(signal.SIGALRM, orig_sigalrm_handler)
27632765
signal.alarm(0)
27642766

27652767
# wait for lock to be removed, with 1 second interval of checking;
@@ -2858,6 +2860,8 @@ def test_toy_lock_cleanup_signals(self):
28582860
locks_dir = os.path.join(self.test_installpath, 'software', '.locks')
28592861
self.assertFalse(os.path.exists(locks_dir))
28602862

2863+
orig_sigalrm_handler = signal.getsignal(signal.SIGALRM)
2864+
28612865
# context manager which stops the function being called with the specified signal
28622866
class wait_and_signal(object):
28632867
def __init__(self, seconds, signum):
@@ -2873,7 +2877,7 @@ def __enter__(self):
28732877

28742878
def __exit__(self, type, value, traceback):
28752879
# clean up SIGALRM signal handler, and cancel scheduled alarm
2876-
signal.signal(signal.SIGALRM, signal.SIG_DFL)
2880+
signal.signal(signal.SIGALRM, orig_sigalrm_handler)
28772881
signal.alarm(0)
28782882

28792883
# add extra sleep command to ensure session takes long enough

0 commit comments

Comments
 (0)