From 9f5cc381d351588155734e15e8f522470dfda70d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Wed, 8 Apr 2020 18:06:51 +0200 Subject: _signals.py: Allow SIGTERM handler to call `os.exit()` Use exit code from the `SystemExit` exception raised by `os.exit()`. --- src/buildstream/_signals.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/buildstream') diff --git a/src/buildstream/_signals.py b/src/buildstream/_signals.py index 425a57239..969789e92 100644 --- a/src/buildstream/_signals.py +++ b/src/buildstream/_signals.py @@ -43,10 +43,14 @@ suspendable_stack = deque() # type: MutableSequence[Callable] # Per process SIGTERM handler def terminator_handler(signal_, frame): + exit_code = -1 + while terminator_stack: terminator_ = terminator_stack.pop() try: terminator_() + except SystemExit as e: + exit_code = e.code or 0 except: # noqa pylint: disable=bare-except # Ensure we print something if there's an exception raised when # processing the handlers. Note that the default exception @@ -62,7 +66,7 @@ def terminator_handler(signal_, frame): # Use special exit here, terminate immediately, recommended # for precisely this situation where child processes are teminated. - os._exit(-1) + os._exit(exit_code) # terminator() -- cgit v1.2.1