diff options
author | Ben Brown <benjamb@pm.me> | 2019-05-10 12:05:01 +0100 |
---|---|---|
committer | Ben Brown <benjamb@pm.me> | 2019-05-10 12:18:36 +0100 |
commit | cf9d17ce9da862e1b70f83bab70c432f190fcea6 (patch) | |
tree | 290a346ce8f6878dc002298586bcfbd8d12ee711 /lorry-controller-minion | |
parent | 8d9de083c35c3e65f438895aa57e1fa73016d123 (diff) | |
download | lorry-controller-cf9d17ce9da862e1b70f83bab70c432f190fcea6.tar.gz |
Ensure child processes of subprocesses are killed with the parentbenbrown/clean-removed-jobs
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.
Diffstat (limited to 'lorry-controller-minion')
-rwxr-xr-x | lorry-controller-minion | 9 |
1 files 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): |