diff options
author | Jürg Billeter <j@bitron.ch> | 2020-04-08 18:06:51 +0200 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2020-04-09 17:53:24 +0000 |
commit | 9f5cc381d351588155734e15e8f522470dfda70d (patch) | |
tree | c398fc0b7c7ad28f00cc767dcac199472b5bb527 /src | |
parent | 358a6dd0c355e5c0c27d099d70c92fc6e9aeef9c (diff) | |
download | buildstream-9f5cc381d351588155734e15e8f522470dfda70d.tar.gz |
_signals.py: Allow SIGTERM handler to call `os.exit()`
Use exit code from the `SystemExit` exception raised by `os.exit()`.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildstream/_signals.py | 6 |
1 files changed, 5 insertions, 1 deletions
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() |