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

Mark Seaborn mrs at mythic-beasts.com
Tue Jun 16 20:04:44 CEST 2009


Cameron Simpson <cs at zip.com.au> wrote:

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 makepipe(): | readfd, writefd = os.pipe() | return os.fdopen(readfd, "r"), os.fdopen(writefd, "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.

Yep. I don't mind closing FDs explicitly when it's easy to do so in a try..finally, but it's not always simple.

There are two different problems with non-prompt closing of FDs:

The second problem could be dealt with by running the GC when we get EMFILE, or before any calls that allocate FDs when the FD table is almost full, just as the GC runs when we "run out" of memory.

I wonder if this proposal could help: 'GC & The "Expensive Object" Problem' http://www.eros-os.org/pipermail/e-lang/1999-May/002590.html

Mark



More information about the Python-Dev mailing list