From cf9d17ce9da862e1b70f83bab70c432f190fcea6 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Fri, 10 May 2019 12:05:01 +0100 Subject: Ensure child processes of subprocesses are killed with the parent Assign a session ID to subprocesses, making it the group leader of any child processes, so that we may clean them up with the parent. --- lorry-controller-minion | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lorry-controller-minion b/lorry-controller-minion index 72f1a39..9eb6657 100755 --- a/lorry-controller-minion +++ b/lorry-controller-minion @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright (C) 2014 Codethink Limited +# Copyright (C) 2014-2019 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ import os import platform import random import select +import signal import subprocess import tempfile import time @@ -171,7 +172,8 @@ class MINION(cliapp.Application): argv, stdin=devnull, stdout=pipe[1], - stderr=subprocess.STDOUT) + stderr=subprocess.STDOUT, + preexec_fn=os.setsid) os.close(pipe[1]) devnull.close() @@ -212,7 +214,8 @@ class MINION(cliapp.Application): return stdout, stderr, exit def kill_job(self): - self.process.kill() + pgid = os.getpgid(self.process.pid) + os.killpg(pgid, signal.SIGKILL) return self.process.wait() def update_webapp_about_job(self, job_spec, stdout, stderr, exit): -- cgit v1.2.1