diff -r 98475e024344 Lib/subprocess.py --- a/Lib/subprocess.py Fri May 30 16:28:00 2014 -0400 +++ b/Lib/subprocess.py Fri May 30 22:06:25 2014 -0700 @@ -1334,16 +1334,42 @@ c2pread, c2pwrite, errread, errwrite) + _fds_dir = None + + if sys.platform.startswith("aix"): + pass + elif sys.platform.startswith("atheos"): + pass + elif sys.platform.startswith("beos"): + pass + elif sys.platform.startswith("darwin"): + pass + elif sys.platform.startswith("freebsd"): + _fds_dir = "/dev/fd" + elif sys.platform.startswith("irix"): + pass + elif sys.platform.startswith("linux"): + _fds_dir = "/proc/self/fd" + elif sys.platform.startswith("mac"): + pass + elif sys.platform.startswith("netbsd"): + _fds_dir = "/dev/fd" + elif sys.platform.startswith("next"): + pass + elif sys.platform.startswith("os2emx"): + pass + elif sys.platform.startswith("riscos"): + pass + elif sys.platform.startswith("sunos"): + pass + elif sys.platform.startswith("unixware"): + pass def _close_fds(self, fds_to_keep): - start_fd = 3 - for fd in sorted(fds_to_keep): - if fd >= start_fd: - os.closerange(start_fd, fd) - start_fd = fd + 1 - if start_fd <= MAXFD: - os.closerange(start_fd, MAXFD) - + for fdstr in os.listdir(_fds_dir): + fd = int(fdstr) + if fd >= 3 and not(fd in fds_to_keep): + os.close(fd) def _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env,