Skip to content

Commit

Permalink
Merge pull request #424 from radical-cybertools/fix/pwatcher_pgkill
Browse files Browse the repository at this point in the history
kill process group also
  • Loading branch information
andre-merzky authored Nov 1, 2024
2 parents 0cb6d17 + 15e1d30 commit 3e1fdd8
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/radical/utils/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


# --------------------------------------------------------------------------
Expand All @@ -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)

Expand All @@ -361,7 +371,6 @@ def unwatch(self, pid):
if pid in self._pids:
self._pids.remove(pid)


# --------------------------------------------------------------------------
#
def _nothing(self, pid):
Expand All @@ -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())


# --------------------------------------------------------------------------
Expand All @@ -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)


# --------------------------------------------------------------------------
Expand Down

0 comments on commit 3e1fdd8

Please sign in to comment.