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

2009-06-18 Thread Facundo Batista
On Sat, Jun 13, 2009 at 9:40 AM, Facundo Batista 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

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

2009-06-16 Thread Mark Seaborn
Cameron Simpson wrote: > On 14Jun2009 16:42, Mark Seaborn 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

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

2009-06-16 Thread Willem Broekema
On Tue, Jun 16, 2009 at 1:21 PM, Michael Foord wrote: > Steven D'Aprano wrote: >> On Tue, 16 Jun 2009 01:20:53 pm Cameron Simpson wrote: >>> I don't think all pythons do immediate ref-counted GC. >> >> Jython and IronPython don't. I don't know about PyPy, CLPython, Unladen >> Swallow, etc. > > PyPy

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

2009-06-16 Thread Michael Foord
Steven D'Aprano wrote: On Tue, 16 Jun 2009 01:20:53 pm Cameron Simpson wrote: I don't think all pythons do immediate ref-counted GC. Jython and IronPython don't. I don't know about PyPy, CLPython, Unladen Swallow, etc. PyPy doesn't, Unladen Swallow won't. Michael -- http://w

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

2009-06-16 Thread Steven D'Aprano
On Tue, 16 Jun 2009 01:20:53 pm Cameron Simpson wrote: > I don't think all > pythons do immediate ref-counted GC. Jython and IronPython don't. I don't know about PyPy, CLPython, Unladen Swallow, etc. -- Steven D'Aprano ___ Python-Dev mailing list Py

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

2009-06-15 Thread Cameron Simpson
On 14Jun2009 16:42, Mark Seaborn 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

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

2009-06-14 Thread Mark Seaborn
Facundo Batista wrote: > errpipe_read, errpipe_write = os.pipe() > try: > try: > . > . > . > . > . > . > finally: > os.close(errpipe_write) > . > . > . > finally: > os.close(errpipe

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

2009-06-13 Thread Facundo Batista
On Fri, Jun 12, 2009 at 9:06 PM, Christian Heimes wrote: > How about a nice 'n shiny context wrapper for the pipe: I'll do this! Thank you for the suggestion! BTW, as this is a good way of avoiding the FD leakage, should this context wrapper for pipe() be in the stdlib? Regards, -- .Facu

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

2009-06-12 Thread Christian Heimes
Facundo Batista wrote: > I just don't like a huge try/finally... but as FDs are just ints, do > you think is there a better way to handle it? How about a nice 'n shiny context wrapper for the pipe: import os class Pipe(object): def __enter__(self): self.read, self.write = os.pipe()

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

2009-06-12 Thread Christian Heimes
Facundo Batista wrote: > I just don't like a huge try/finally... but as FDs are just ints, do > you think is there a better way to handle it? How about a nice 'n shiny context wrapper for the pipe: import os class Pipe(object): def __enter__(self): self.read, self.write = os.pipe()

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

2009-06-12 Thread Facundo Batista
In a long lived process at work, we started leaking file descriptors. The problem were that subprocess.Popen._execute_child() method creates two files descriptors through a call to os.pipe(), and after some work it closes them. But an os.read() on the descriptor was interrupted (EINTR), so an exce