Skip to content

Commit

Permalink
Reimplement CommandManager.kill in terms of kill_processes_and_descen…
Browse files Browse the repository at this point in the history
…dants
  • Loading branch information
filipcacky committed Oct 22, 2024
1 parent 2dfa714 commit 1286f0f
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions metaflow/runner/subprocess_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,6 @@
from .utils import check_process_exited


def kill_process_and_descendants(pid, termination_timeout):
# TODO: there's a race condition that new descendants might
# spawn b/w the invocations of 'pkill' and 'kill'.
# Needs to be fixed in future.
try:
subprocess.check_call(["pkill", "-TERM", "-P", str(pid)])
subprocess.check_call(["kill", "-TERM", str(pid)])
except subprocess.CalledProcessError:
pass

time.sleep(termination_timeout)

try:
subprocess.check_call(["pkill", "-KILL", "-P", str(pid)])
subprocess.check_call(["kill", "-KILL", str(pid)])
except subprocess.CalledProcessError:
pass


def kill_processes_and_descendants(pids: List[str], termination_timeout: float):
# TODO: there's a race condition that new descendants might
# spawn b/w the invocations of 'pkill' and 'kill'.
Expand Down Expand Up @@ -528,7 +509,7 @@ def kill(self, termination_timeout: float = 2):
"""

if self.process is not None:
kill_process_and_descendants(self.process.pid, termination_timeout)
kill_processes_and_descendants([str(self.process.pid)], termination_timeout)
else:
print("No process to kill.")

Expand Down

0 comments on commit 1286f0f

Please sign in to comment.