diff -r ad1cc596bedb Lib/subprocess.py --- a/Lib/subprocess.py Wed Oct 24 23:43:02 2012 +0300 +++ b/Lib/subprocess.py Thu Oct 25 15:25:20 2012 -0700 @@ -671,12 +671,20 @@ c2pread, c2pwrite, errread, errwrite) = self._get_handles(stdin, stdout, stderr) - self._execute_child(args, executable, preexec_fn, close_fds, - cwd, env, universal_newlines, - startupinfo, creationflags, shell, - p2cread, p2cwrite, - c2pread, c2pwrite, - errread, errwrite) + try: + self._execute_child(args, executable, preexec_fn, close_fds, + cwd, env, universal_newlines, + startupinfo, creationflags, shell, + p2cread, p2cwrite, + c2pread, c2pwrite, + errread, errwrite) + except OSError: + for handle in (p2cread, p2cwrite, + c2pread, c2pwrite, + errread, errwrite): + if handle is not None: + os.close(handle) + raise if mswindows: if p2cwrite is not None: