Skip to content

Commit 857c14d

Browse files
committed
Handle case where orig_handler might be None
Signed-off-by: David Gardner <dagardner@nvidia.com>
1 parent 9282b5c commit 857c14d

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

ci/scripts/run_tests.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,15 @@ def main(junit_xml: str | None,
244244

245245
failures = 0
246246

247+
orig_handler = signal.getsignal(signal.SIGINT)
248+
249+
def _restore_handler():
250+
if orig_handler is not None:
251+
signal.signal(signal.SIGINT, orig_handler)
252+
247253
with Pool(processes=jobs) as pool:
248254
ex = pool
249255

250-
orig_handler = signal.getsignal(signal.SIGINT)
251-
252256
def shutdown_pool(_signum, _frame):
253257
nonlocal ex
254258

@@ -263,7 +267,7 @@ def shutdown_pool(_signum, _frame):
263267
else:
264268
print("Pool not found")
265269

266-
signal.signal(signal.SIGINT, orig_handler)
270+
_restore_handler()
267271
raise SystemExit(shutdown_msg)
268272

269273
signal.signal(signal.SIGINT, shutdown_pool)
@@ -291,6 +295,7 @@ def shutdown_pool(_signum, _frame):
291295
shutdown_pool(None, None)
292296
finally:
293297
ex = None
298+
_restore_handler()
294299
for p in projects:
295300
sh(["rm", "-rf", str(p / ".venv")])
296301

0 commit comments

Comments
 (0)