classification
Title: subprocess.Popen close_fds behaviour differs between 3.2 and 3.4
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.2, Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, mfs, vstinner
Priority: normal Keywords:

Created on 2015-01-21 10:37 by mfs, last changed 2015-01-21 14:37 by r.david.murray. This issue is now closed.

Messages (4)
msg234428 - (view) Author: Mike Sampson (mfs) Date: 2015-01-21 10:37
I'm seeing differing behaviour with subprocess.Popen(..., close_fds = False) between 3.2 and 3.4. The docs don't say this is meant to be the case as far as I can see.

Python 3.2.3 on Debian Wheezy
=============================

>>> import subprocess
>>> import os
>>> r,w = os.pipe()
>>> p = subprocess.Popen('ls /dev/fd/*', shell = True, close_fds = False)
>>> ls: cannot access /dev/fd/5: No such file or directory
/dev/fd/0  /dev/fd/1  /dev/fd/2  /dev/fd/3  /dev/fd/4

Python 3.4.2 on Arch Linux
==========================

>>> import subprocess
>>> import os
>>> r,w = os.pipe()
>>> p = subprocess.Popen('ls /dev/fd/*', shell = True, close_fds = False)                                                                                                            
>>> ls: cannot access /dev/fd/3: No such file or directory
/dev/fd/0  /dev/fd/1  /dev/fd/2

In 3.4 even though close_fds is False the fds are closed in the child. Using pass_fds works around this though I would like to know if this is a bug, documentation issue, or am I missing something here?
msg234429 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-01-21 10:39
File descriptors are not closed, but not inherited neither, in Python 3.4. See the PEP 446.

To have a reliable behaviour on all platforms and all Python versions, just use the pass_fds parameter.
msg234430 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-01-21 10:40
https://docs.python.org/dev/library/os.html#os.pipe

Changed in version 3.4: The new file descriptors are now non-inheritable.

If you don't use the subprocess module, you may use os.set_inheritable().
https://docs.python.org/dev/library/os.html#os.set_inheritable
msg234431 - (view) Author: Mike Sampson (mfs) Date: 2015-01-21 10:43
Ah, got it. Didn't see the note on the os.pipe() docs. Thanks. Closing. Sorry for the noise.
History
Date User Action Args
2015-01-21 14:37:30r.david.murraysetresolution: not a bug
stage: resolved
2015-01-21 10:43:25mfssetstatus: open -> closed
2015-01-21 10:43:08mfssetmessages: + msg234431
2015-01-21 10:40:22vstinnersetmessages: + msg234430
2015-01-21 10:39:19vstinnersetnosy: + vstinner
messages: + msg234429
2015-01-21 10:37:56mfscreate