Red Hat Bugzilla – Bug 667431
Python Popen.communicate is unable to collect stderr, stdout and returncode for a short lived processes
Last modified: 2016-05-31 21:40:58 EDT
Created attachment 471885 [details]
Description of problem:
Using Popen.communicate over a short-lived process results in a broken pipe exception (errno 32) which will prevent to collect the stderr, stdout and returncode of the dead process.
Version-Release number of selected component (if applicable):
# rpm -qf /usr/lib64/python2.6/subprocess.py
$ python test_shortprocess.py
Traceback (most recent call last):
File "test_shortprocess.py", line 7, in <module>
out, err = p.communicate(2**20 * '\0')
File "/usr/lib64/python2.7/subprocess.py", line 740, in communicate
File "/usr/lib64/python2.7/subprocess.py", line 1256, in _communicate
stdout, stderr = self._communicate_with_poll(input)
File "/usr/lib64/python2.7/subprocess.py", line 1319, in _communicate_with_poll
input_offset += os.write(fd, chunk)
OSError: [Errno 32] Broken pipe
$ python test_process-fix.py
dd: unrecognized operand `option=crash'
Try `dd --help' for more information.
Created attachment 471886 [details]
Proposed patch for el6.
Created attachment 471887 [details]
Proposed patch for fc14.
Thanks for filing this bug.
I've filed it within the upstream python tracker as:
The patch I've attached there slightly reworks the fix, and adds a unit test.
However, I'm not fully convinced that this is the correct approach, in that the change could mask stdin under-reads from poorly-written subprocesses that exit with failures but don't return with a non-zero exit code (alas, too many programs exit with 0 even when exiting with an error).
Development Management has reviewed and declined this request. You may appeal
this decision by reopening this request.
Created attachment 490627 [details]
Backport of the upstream patch
The attached patch is a backport of the patch applied upstream to 2.7 to the somewhat modified 2.6.6 currently in RHEL 6.1
The upstream patch contained two new test cases; I've added some additional cases over and above those ones. All of test/test_subprocess.py passes on my test build (x86_64; python-2.6.6-17 + this new patch)
I've also tested the patched version using attachment 471885 [details] (from comment #0), and it fixes the reported traceback, giving the expected results.
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.
For information on the advisory, and where to find the updated
files, follow the link below.
If the solution does not work for you, open a new bug report.