[Python-Dev] Avoiding file descriptors leakage in subprocess.Popen()

Cameron Simpson cs at zip.com.au
Tue Jun 16 05:20:53 CEST 2009

On 14Jun2009 16:42, Mark Seaborn <mrs at mythic-beasts.com> wrote:
| I use a convenience function like this, so that GC takes care of the FDs:
| def make_pipe():
|     read_fd, write_fd = os.pipe()
|     return os.fdopen(read_fd, "r"), os.fdopen(write_fd, "w")

Not guarrenteed to be timely. The try/except at least closes things as
control passes out of the relevant scope. I don't think all pythons
do immediate ref-counted GC.

But it's very neat!
Cameron Simpson <cs at zip.com.au> DoD#743

Trust the computer industry to shorten Year 2000 to Y2K. It was this
thinking that caused the problem in the first place.
- Mark Ovens <marko at uk.radan.com>

More information about the Python-Dev mailing list