[New-bugs-announce] [issue12739] read stuck with multithreading and simultaneous subprocess.Popen

Joe Hu report at bugs.python.org
Fri Aug 12 05:20:24 CEST 2011

New submission from Joe Hu <sapikachu at gmail.com>:

When multiple threads create child processes simultaneously and redirect their stdout using subprocess.Popen, at least one thread will stuck on reading the stdout after its child process exited, until all other processes are also exited.

The test case reproduces the problem. It's always reproducible on my system (Python 3.1 on Windows 7 x64 / Python 3.2 on Windows 7 x86).

Here is my suspicion: 
When Popen is called by two threads simultaneously, the latter child processes may be started before pipe handles for the former process are closed, causing the handles be incorrectly inherited by the latter process. So these handles can only be closed after all the two processes exit, and only after that, p.stdout.read* can detect EOF and return.

components: Library (Lib), Windows
files: python-subprocess-bug-test-case.py
messages: 141939
nosy: SAPikachu
priority: normal
severity: normal
status: open
title: read stuck with multithreading and simultaneous subprocess.Popen
type: behavior
versions: Python 3.1, Python 3.2
Added file: http://bugs.python.org/file22885/python-subprocess-bug-test-case.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list