Index: Lib/popen2.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/popen2.py,v retrieving revision 1.26 diff -w -u -r1.26 popen2.py --- Lib/popen2.py 2 Jun 2003 19:12:01 -0000 1.26 +++ Lib/popen2.py 29 Jun 2003 03:07:16 -0000 @@ -19,6 +19,13 @@ for inst in _active[:]: inst.poll() +def _cleanup_fds(fdlist): + for fd in fdlist: + try: + os.close(fd) + except OSError: + pass + class Popen3: """Class representing a child process. Normally instances are created by the factory functions popen2() and popen3().""" @@ -36,6 +43,7 @@ c2pread, c2pwrite = os.pipe() if capturestderr: errout, errin = os.pipe() + try: self.pid = os.fork() if self.pid == 0: # Child @@ -54,6 +62,12 @@ else: self.childerr = None _active.append(self) + except: + fdlist = [p2cread, p2cwrite, c2pread, c2pwrite] + if capturestderr: + fdlist += [errout, errin] + _cleanup_fds(fdlist) + raise def _run_child(self, cmd): if isinstance(cmd, basestring): @@ -98,6 +112,7 @@ _cleanup() p2cread, p2cwrite = os.pipe() c2pread, c2pwrite = os.pipe() + try: self.pid = os.fork() if self.pid == 0: # Child @@ -110,6 +125,9 @@ os.close(c2pwrite) self.fromchild = os.fdopen(c2pread, 'r', bufsize) _active.append(self) + except: + _cleanup_fds([p2cread, p2cwrite, c2pread, c2pwrite]) + raise if sys.platform[:3] == "win" or sys.platform == "os2emx":