summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-04-08 17:44:52 +0200
committerbst-marge-bot <marge-bot@buildstream.build>2020-04-09 17:53:24 +0000
commit637a1259822a64da0c6758d3632f0cc990a49520 (patch)
treed57efa270cc625a068b6ccad461b5305cd4baa59
parent9f5cc381d351588155734e15e8f522470dfda70d (diff)
downloadbuildstream-637a1259822a64da0c6758d3632f0cc990a49520.tar.gz
job.py: Use `_signals.terminator()` to handle `SIGTERM`
`Sandbox` subclasses use `_signals.terminator()` to gracefully terminate the running command and cleanup the sandbox. Setting a `SIGTERM` handler in `job.py` breaks this.
-rw-r--r--src/buildstream/_scheduler/jobs/job.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/buildstream/_scheduler/jobs/job.py b/src/buildstream/_scheduler/jobs/job.py
index b4060910b..823404b59 100644
--- a/src/buildstream/_scheduler/jobs/job.py
+++ b/src/buildstream/_scheduler/jobs/job.py
@@ -688,17 +688,15 @@ class ChildJob:
nonlocal starttime
starttime += datetime.datetime.now() - stopped_time
+ # Graciously handle sigterms.
+ def handle_sigterm():
+ self._child_shutdown(_ReturnCode.TERMINATED)
+
# Time, log and and run the action function
#
- with _signals.suspendable(stop_time, resume_time), self._messenger.recorded_messages(
- self._logfile, self._logdir
- ) as filename:
-
- # Graciously handle sigterms.
- def handle_sigterm(_signum, _sigframe):
- self._child_shutdown(_ReturnCode.TERMINATED)
-
- signal.signal(signal.SIGTERM, handle_sigterm)
+ with _signals.terminator(handle_sigterm), _signals.suspendable(
+ stop_time, resume_time
+ ), self._messenger.recorded_messages(self._logfile, self._logdir) as filename:
self.message(MessageType.START, self.action_name, logfile=filename)