◐ Shell
clean mode source ↗

bpo-37424: Avoid a hang in subprocess.run timeout output capture by gpshead · Pull Request #14490 · python/cpython

added 2 commits

June 30, 2019 16:46
When shell=True the user is often launching a process tree, if we
kill only the shell and it hasn't set itself up as a pgrp leader,
the grandchild processes still run and may have our output handles
open.  Leading us to wait forever when we should be timing out.

This Adds a fractional timeout on the cleanup communicate phase
_and_ will use killpg on the child process group _if_ it is
different from our own as it should be when start_new_session=True
was used.

@gpshead gpshead changed the title bpo-issue37424: Avoid a hang in subprocess.run timeout output capture bpo-37424: Avoid a hang in subprocess.run timeout output capture

Jul 1, 2019

giampaolo

vstinner

Do not have a post-timeout sub-timeout for output collection, we've already
got all of that output within POSIX's _communicate() method as it is.

gpshead

that belongs in its own PR if at all.
it wasn't actually testing what it described as it never checked
the grandchild process explicitly.  redo this better in a later PR.

Yhg1s

@gpshead

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request

Sep 11, 2019
…honGH-14490)

Fixes a possible hang when using a timeout on subprocess.run() while
capturing output. If the child process spawned its own children or otherwise
connected its stdout or stderr handles with another process, we could hang
after the timeout was reached and our child was killed when attempting to read
final output from the pipes.
(cherry picked from commit 580d278)

Co-authored-by: Gregory P. Smith <greg@krypto.org>

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request

Sep 11, 2019
…honGH-14490)

Fixes a possible hang when using a timeout on subprocess.run() while
capturing output. If the child process spawned its own children or otherwise
connected its stdout or stderr handles with another process, we could hang
after the timeout was reached and our child was killed when attempting to read
final output from the pipes.
(cherry picked from commit 580d278)

Co-authored-by: Gregory P. Smith <greg@krypto.org>

miss-islington added a commit that referenced this pull request

Sep 11, 2019
…14490)

Fixes a possible hang when using a timeout on subprocess.run() while
capturing output. If the child process spawned its own children or otherwise
connected its stdout or stderr handles with another process, we could hang
after the timeout was reached and our child was killed when attempting to read
final output from the pipes.
(cherry picked from commit 580d278)

Co-authored-by: Gregory P. Smith <greg@krypto.org>

miss-islington added a commit that referenced this pull request

Sep 11, 2019
…14490)

Fixes a possible hang when using a timeout on subprocess.run() while
capturing output. If the child process spawned its own children or otherwise
connected its stdout or stderr handles with another process, we could hang
after the timeout was reached and our child was killed when attempting to read
final output from the pipes.
(cherry picked from commit 580d278)

Co-authored-by: Gregory P. Smith <greg@krypto.org>

websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request

Jul 20, 2020
…honGH-14490)

Fixes a possible hang when using a timeout on subprocess.run() while
capturing output. If the child process spawned its own children or otherwise
connected its stdout or stderr handles with another process, we could hang
after the timeout was reached and our child was killed when attempting to read
final output from the pipes.