--- subprocess.py.orig 2010-07-14 21:36:16.000000000 +0600 +++ subprocess.py 2011-06-03 16:03:25.462114581 +0600 @@ -966,6 +966,7 @@ pass elif stdin == PIPE: p2cread, p2cwrite = os.pipe() + self._set_cloexec_flag(p2cread) elif isinstance(stdin, int): p2cread = stdin else: @@ -976,6 +977,7 @@ pass elif stdout == PIPE: c2pread, c2pwrite = os.pipe() + self._set_cloexec_flag(c2pwrite) elif isinstance(stdout, int): c2pwrite = stdout else: @@ -986,6 +988,7 @@ pass elif stderr == PIPE: errread, errwrite = os.pipe() + self._set_cloexec_flag(errwrite) elif stderr == STDOUT: errwrite = c2pwrite elif isinstance(stderr, int): @@ -1072,15 +1075,6 @@ if errwrite is not None: os.dup2(errwrite, 2) - # Close pipe fds. Make sure we don't close the same - # fd more than once, or standard fds. - if p2cread is not None and p2cread not in (0,): - os.close(p2cread) - if c2pwrite is not None and c2pwrite not in (p2cread, 1): - os.close(c2pwrite) - if errwrite is not None and errwrite not in (p2cread, c2pwrite, 2): - os.close(errwrite) - # Close all other fds, if asked for if close_fds: self._close_fds(but=errpipe_write)