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

Facundo Batista facundobatista at gmail.com
Thu Jun 18 22:07:02 CEST 2009

On Sat, Jun 13, 2009 at 9:40 AM, Facundo
Batista<facundobatista at gmail.com> wrote:

>> How about a nice 'n shiny context wrapper for the pipe:
> I'll do this!
> Thank you for the suggestion!

Boo, I can not take this approach, neither the previous one.

The reason is very specific for subprocess.py... after creating the
FDs, it forks(), and the behaviour of when closing which descriptors
are different for the parent and child processes.  If I take Christian
approach, the test just hangs. One drawback of the "with" usage is
that it closes both FDs at the same time... and in this case this may
be a problem, as they're used and closed by different processes in
different times... don't know.

I also tried the approach of wrapping the FDs with a file object...
this *almost* work... but in the case of a problem in the child
process, when a traceback should be written through the pipe to the
parent, nothing happens (it seems that the GC just closes the object
and the info is not transferred).

So, I'll stick to the code I submitted to the bug, because even if
it's ugly it works.

.    Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/

More information about the Python-Dev mailing list