From 637a1259822a64da0c6758d3632f0cc990a49520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Wed, 8 Apr 2020 17:44:52 +0200 Subject: 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. --- src/buildstream/_scheduler/jobs/job.py | 16 +++++++--------- 1 file 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) -- cgit v1.2.1