From 15e1d305363c67cf877ccbad17176828b4fb58b6 Mon Sep 17 00:00:00 2001 From: Andre Merzky Date: Fri, 1 Nov 2024 04:08:25 +0100 Subject: [PATCH] kill process group also --- src/radical/utils/heartbeat.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/radical/utils/heartbeat.py b/src/radical/utils/heartbeat.py index 5feaf22b..0496fbb7 100644 --- a/src/radical/utils/heartbeat.py +++ b/src/radical/utils/heartbeat.py @@ -309,12 +309,21 @@ def __init__(self, action=None, uid=None, log=None): # -------------------------------------------------------------------------- # def _is_alive(self, pid): - try: - os.kill(pid, 0) - except OSError: - return False - else: - return True + + try : os.kill(pid, 0) + except OSError: return False + else : return True + + + # -------------------------------------------------------------------------- + # + def _kill(self, pid): + + try : os.killpg(pid, signal.SIGTERM) + except: pass + + try : os.kill(pid, signal.SIGTERM) + except: pass # -------------------------------------------------------------------------- @@ -334,7 +343,8 @@ def _watch(self): self._log.warn('process %d died, exit', pid) self._pids.remove(pid) - if self._action == self.SUICIDE: self._suicide(pid) + if self._action == self.NOTHING: self._nothing(pid) + elif self._action == self.SUICIDE: self._suicide(pid) elif self._action == self.KILLALL: self._killall(pid) elif self._action == self.RAMPAGE: self._rampage(pid) @@ -361,7 +371,6 @@ def unwatch(self, pid): if pid in self._pids: self._pids.remove(pid) - # -------------------------------------------------------------------------- # def _nothing(self, pid): @@ -374,7 +383,7 @@ def _nothing(self, pid): def _suicide(self, pid): self._log.debug("process %d's demise triggered suicide", pid) - os.kill(os.getpid(), signal.SIGKILL) + self._kill(os.getpid()) # -------------------------------------------------------------------------- @@ -385,8 +394,7 @@ def _killall(self, pid): pid, self._pids) for pid in list(self._pids): - try : os.kill(pid, signal.SIGKILL) - except: pass + self._kill(pid) # --------------------------------------------------------------------------