Skip to content

Commit 5e33b4f

Browse files
committed
fix: localmode subprocess parent process not sending SIGTERM to child
1 parent 1d84830 commit 5e33b4f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/sagemaker/local/image.py

+2
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,8 @@ def run(self):
840840

841841
def down(self):
842842
"""Placeholder docstring"""
843+
if os.name != 'nt':
844+
sagemaker.local.utils.kill_child_processes(self.process.pid)
843845
self.process.terminate()
844846

845847

src/sagemaker/local/utils.py

+22
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import os
1717
import shutil
18+
import subprocess
1819

1920
from distutils.dir_util import copy_tree
2021
from six.moves.urllib.parse import urlparse
@@ -88,3 +89,24 @@ def recursive_copy(source, destination):
8889
"""
8990
if os.path.isdir(source):
9091
copy_tree(source, destination)
92+
93+
94+
def kill_child_processes(pid):
95+
child_pids = get_child_process_ids(pid)
96+
for pid in child_pids:
97+
os.kill(pid, 15)
98+
99+
100+
def get_child_process_ids(pid):
101+
cmd = f"pgrep -P {pid}".split()
102+
output, err = subprocess.Popen(
103+
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
104+
).communicate()
105+
if err:
106+
return []
107+
pids = [int(pid) for pid in output.decode('utf-8').split()]
108+
if pids:
109+
for pid in pids:
110+
return pids + get_child_process_ids(pid)
111+
else:
112+
return []

0 commit comments

Comments
 (0)