Skip to content
Closed
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def check_output(*popenargs, timeout=None, **kwargs):
b'when in the course of barman events\n'

By default, all communication is in bytes, and therefore any "input"
should be bytes, and the return value wil be bytes. If in text mode,
should be bytes, and the return value will be bytes. If in text mode,
any "input" should be a string, and the return value will be a string
decoded according to locale encoding, or by "encoding" if set. Text mode
is triggered by setting any of text, encoding, errors or universal_newlines.
Expand Down Expand Up @@ -1728,7 +1728,10 @@ def send_signal(self, sig):
"""Send a signal to the process."""
# Skip signalling a process that we know has already died.
if self.returncode is None:
os.kill(self.pid, sig)
# Issue32795
# Send signal to the whole process group to prevent
# making the subprocess a zombie due to its subprocesses
os.killpg(self.pid, sig)

def terminate(self):
"""Terminate the process with SIGTERM
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Subprocess now become process group leaders, so its spawned sub-subprocesses
can get killed properly. Patch by Fangyi Zhou.
3 changes: 3 additions & 0 deletions Modules/_posixsubprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,9 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
PyOS_AfterFork_Child();
}

/* Make child process a process group leader */
setpgid(0, 0);

child_exec(exec_array, argv, envp, cwd,
p2cread, p2cwrite, c2pread, c2pwrite,
errread, errwrite, errpipe_read, errpipe_write,
Expand Down