From 9f1c4013fe7bc6fe6d4ebedf6dfb58c72585870c Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Wed, 27 Jan 2021 04:38:25 +0000 Subject: [PATCH] Fix: release signal handlers after execution After a process has executed, return the signal handlers to their original state. --- aiida/engine/runners.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/aiida/engine/runners.py b/aiida/engine/runners.py index 7708c851b5..6c76208c42 100644 --- a/aiida/engine/runners.py +++ b/aiida/engine/runners.py @@ -238,10 +238,17 @@ def kill_process(_num, _frame): LOGGER.critical('runner received interrupt, killing process %s', process_inited.pid) process_inited.kill(msg='Process was killed because the runner received an interrupt') - signal.signal(signal.SIGINT, kill_process) - signal.signal(signal.SIGTERM, kill_process) + original_handler_int = signal.getsignal(signal.SIGINT) + original_handler_term = signal.getsignal(signal.SIGTERM) + + try: + signal.signal(signal.SIGINT, kill_process) + signal.signal(signal.SIGTERM, kill_process) + process_inited.execute() + finally: + signal.signal(signal.SIGINT, original_handler_int) + signal.signal(signal.SIGTERM, original_handler_term) - process_inited.execute() return process_inited.outputs, process_inited.node def run(self, process: TYPE_RUN_PROCESS, *args: Any, **inputs: Any) -> Dict[str, Any]: