[ python-Bugs-1604851 ] subprocess.Popen closes fds for sys.stdout or sys.stderr
SourceForge.net
noreply at sourceforge.net
Tue Dec 19 15:32:52 CET 2006
Bugs item #1604851, was opened at 2006-11-28 17:17
Message generated for change (Settings changed) made by akuchling
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1604851&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Nishkar Grover (ngrover)
>Assigned to: Peter Åstrand (astrand)
Summary: subprocess.Popen closes fds for sys.stdout or sys.stderr
Initial Comment:
I found a problem in subprocess.Popen's _execute_child() method for POSIX, where the child process will close the fds for sys.stdout and/or sys.stderr if I use those as stdout and/or stderr when creating a subprocess.Popen object.
Here's what I saw by default when using the 2.4.4 version of Python...
% ./python
Python 2.4.4 (#1, Nov 28 2006, 14:08:29)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import sys, subprocess
>>> uname = subprocess.Popen('uname -a', shell=True, stdout=sys.stdout)
>>> uname: write error: Bad file descriptor
>>>
Then, I updated subprocess.py and made the following changes...
% diff subprocess.py subprocess.py.orig
924c924
< # fd more than once and don't close sys.stdout or sys.stderr.
---
> # fd more than once.
927c927
< if c2pwrite and c2pwrite not in (p2cread, sys.stdout.fileno(), sys.stderr.fileno()):
---
> if c2pwrite and c2pwrite not in (p2cread,):
929c929
< if errwrite and errwrite not in (p2cread, c2pwrite, sys.stdout.fileno(), sys.stderr.fileno()):
---
> if errwrite and errwrite not in (p2cread, c2pwrite):
After that, I saw the following...
% ./python
Python 2.4.4 (#1, Nov 28 2006, 14:08:29)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import sys, subprocess
>>> uname = subprocess.Popen('uname -a', shell=True, stdout=sys.stdout)
>>> Linux schnauzer 2.6.9-42.0.2.ELsmp #1 SMP Thu Aug 17 18:00:32 EDT 2006 i686 i686 i386 GNU/Linux
>>>
I'm attaching the modified version of subprocess.py. Please consider adding this fix to future versions of Python. Thanks!
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1604851&group_id=5470
More information about the Python-bugs-list
mailing list