Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kill process group also #424

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading