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

Mark Seaborn mrs at mythic-beasts.com
Sun Jun 14 17:42:55 CEST 2009


Facundo Batista <facundobatista at gmail.com> wrote:

errpiperead, errpipewrite = os.pipe() try: try: ..... ..... ..... ..... ..... ..... finally: os.close(errpipewrite) ..... ..... ..... finally: os.close(errpiperead)

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?

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")

Mark



More information about the Python-Dev mailing list