diff options
author | Jürg Billeter <j@bitron.ch> | 2020-04-08 17:44:52 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2020-04-08 18:20:51 +0200 |
commit | 7e16744524295b4c81ef9f5f67a0c108534e8521 (patch) | |
tree | ea952a9e6fad904e4dc966f144927a99a4b9d92a | |
parent | 18c4ee0daf92657b04dc7e2f5321602025ff30e5 (diff) | |
download | buildstream-7e16744524295b4c81ef9f5f67a0c108534e8521.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.py | 16 |
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) |