summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-01-04 19:07:07 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-01-04 19:07:07 (GMT)
commitc99823211bfc349ae48ff00a9155472ccea0816d (patch)
tree7030ed63760ac2bcc9dd29300b41ecb58c13f7cc /Lib/subprocess.py
parent9bd4a245f2ed0ce5a59652976c19ca74e9db518f (diff)
downloadcpython-c99823211bfc349ae48ff00a9155472ccea0816d.zip
cpython-c99823211bfc349ae48ff00a9155472ccea0816d.tar.gz
cpython-c99823211bfc349ae48ff00a9155472ccea0816d.tar.bz2
In subprocess, wrap pipe fds before launching the child. Hopefully this
will fix intermittent failures on some buildbots (issue #8458).
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 5c5e9f2..c02fb52 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -699,13 +699,9 @@ class Popen(object):
c2pread, c2pwrite,
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
- self._execute_child(args, executable, preexec_fn, close_fds,
- pass_fds, cwd, env, universal_newlines,
- startupinfo, creationflags, shell,
- p2cread, p2cwrite,
- c2pread, c2pwrite,
- errread, errwrite,
- restore_signals, start_new_session)
+ # We wrap OS handles *before* launching the child, otherwise a
+ # quickly terminating child could make our fds unwrappable
+ # (see #8458).
if mswindows:
if p2cwrite != -1:
@@ -730,6 +726,24 @@ class Popen(object):
if universal_newlines:
self.stderr = io.TextIOWrapper(self.stderr)
+ try:
+ self._execute_child(args, executable, preexec_fn, close_fds,
+ pass_fds, cwd, env, universal_newlines,
+ startupinfo, creationflags, shell,
+ p2cread, p2cwrite,
+ c2pread, c2pwrite,
+ errread, errwrite,
+ restore_signals, start_new_session)
+ except:
+ # Cleanup if the child failed starting
+ for f in filter(None, [self.stdin, self.stdout, self.stderr]):
+ try:
+ f.close()
+ except EnvironmentError:
+ # Ignore EBADF or other errors
+ pass
+ raise
+
def _translate_newlines(self, data, encoding):
data = data.replace(b"\r\n", b"\n").replace(b"\r", b"\n")