This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author justincappos
Recipients justincappos
Date 2008-06-19.19:18:19
SpamBayes Score 0.27755767
Marked as misclassified No
Message-id <1213903108.91.0.624214427386.issue3144@psf.upfronthosting.co.za>
In-reply-to
Content
The behavior of popen vs popen[2-4] differs with respect to open file
descriptors (at least on the Linux implementation of popen).   popen
does not close file descriptors, thus processes retain open file
descriptors from their parent.   This is likely not desirable for
security and stability reasons.   

If this isn't fixed, at a minimum it would be a good thing to document.


Here is an example that demonstrates the issue:

<<< start of open_and_popen.py>>>
# This will not be printed if popen closes file descriptors

import os
myfd = os.open("open_and_popen.py",os.O_RDONLY)

readfo = os.popen("python print_from_fd.py "+str(myfd),"r")

print "os.popen results in:"
print readfo.read()
# it will print the first line of the file here
readfo.close()


(junkinfo, readfo) = os.popen2("python print_from_fd.py "+str(myfd),"r")
junkinfo.close()

print "os.popen2 results in:"
print readfo.read()
# the child got an error, so this is just the error text
readfo.close()

os.close(myfd)
<<< end of open_and_popen.py>>>


<<< start of print_from_fd.py>>>
import os
import sys
print os.read(int(sys.argv[1]),60)
<<< end of print_from_fd.py>>>
History
Date User Action Args
2008-06-19 19:18:29justincappossetspambayes_score: 0.277558 -> 0.27755767
recipients: + justincappos
2008-06-19 19:18:29justincappossetspambayes_score: 0.277558 -> 0.277558
messageid: <1213903108.91.0.624214427386.issue3144@psf.upfronthosting.co.za>
2008-06-19 19:18:27justincapposlinkissue3144 messages
2008-06-19 19:18:25justincapposcreate