[issue6559] [PATCH]add pass_fds paramter to subprocess.Popen()

Milko Krachounov report at bugs.python.org
Sat Dec 11 15:04:55 CET 2010


Milko Krachounov <python at milko.3mhz.net> added the comment:

The patch doesn't seem to work.

I added this before closerange in _close_all_but_a_sorted_few_fds:

print("Closing", start_fd, "up to", fd, "exclusive")

And used the attached script to run as a subprocess to check for open fds (taken from my tests patch for issue 7213).

Here's the result:
Python 3.2b1 (py3k:87158M, Dec 11 2010, 02:55:28) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import os
>>> import subprocess
>>> subprocess.Popen([sys.executable, 'fd_status.py'], close_fds=False).wait()
0,1,2
0
>>> os.pipe()
(3, 4)
>>> os.pipe()
(5, 6)
>>> subprocess.Popen([sys.executable, 'fd_status.py'], close_fds=False).wait()
0,1,2,3,4,5,6
0
>>> subprocess.Popen([sys.executable, 'fd_status.py'], close_fds=True).wait()
0,1,2
0
>>> subprocess.Popen([sys.executable, 'fd_status.py'], close_fds=True, pass_fds=(6,)).wait()
0,1,2,6
0
>>> subprocess.Popen([sys.executable, 'fd_status.py'], close_fds=True, pass_fds=(3,)).wait()
0,1,2
0
>>> subprocess._posixsubprocess = None
>>> subprocess.Popen([sys.executable, 'fd_status.py'], close_fds=True, pass_fds=(6,)).wait()
Closing 3 up to 6 exclusive
Closing 7 up to 8 exclusive
0,1,2,6
0
>>> subprocess.Popen([sys.executable, 'fd_status.py'], close_fds=True, pass_fds=(3,)).wait()
Closing 3 up to 8 exclusive
0,1,2
0

I also attach a possible test for pass_fds, and an example fix for Python-only implementation. The test requires either my tests patch for issue 7213, or the attached fd_status.py to be put in subprocessdata subdir of Lib/test. The fixed Python implementation passes my test and works fine in the console, I haven't tried the C one. (I don't have a patch for the fix, since it would conflict with the patches for issue 7213.)

----------
nosy: +milko.krachounov
Added file: http://bugs.python.org/file20010/fd_status.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6559>
_______________________________________


More information about the Python-bugs-list mailing list