[New-bugs-announce] [issue31935] subprocess.run() timeout not working with grandchildren and stdout=PIPE

Martin Ritter report at bugs.python.org
Fri Nov 3 11:01:32 EDT 2017


New submission from Martin Ritter <mce.ritter at gmail.com>:

Hi,

I tried to use 

    subprocess.run(..., stdout=subprocess.PIPE, timeout=N)

to run some test scripts with a given timeout. 

This works as expected with simple scripts. However if the script itself creates other children which write to stdout then `subprocess.run()` seems to wait for all of the children to finish. I've attached a minimal example.

I looked into subprocess.py and `subprocess.run()` calls `process.communicate()` again without timeout when handling the TimeoutExpired exception which then in turn waits for the pipes to be closed by all children.

If communicate() would check if the process is still alive while waiting for output and close the pipes once the process has finished the timeout feature should work as expected and descendants would get a SIGPIPE when writing to stdout/stderr.

----------
components: Library (Lib)
files: test_killsub.py
messages: 305487
nosy: Martin Ritter
priority: normal
severity: normal
status: open
title: subprocess.run() timeout not working with grandchildren and stdout=PIPE
type: behavior
versions: Python 3.6
Added file: https://bugs.python.org/file47251/test_killsub.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31935>
_______________________________________


More information about the New-bugs-announce mailing list