[Python-checkins] bpo-30121: Fix debug assert in subprocess on Windows (#1224)
Victor Stinner
webhook-mailer at python.org
Fri Aug 18 09:18:18 EDT 2017
https://github.com/python/cpython/commit/4d3851727fb82195e4995c6064b0b2d6cbc031c4
commit: 4d3851727fb82195e4995c6064b0b2d6cbc031c4
branch: master
author: Segev Finer <segev208 at gmail.com>
committer: Victor Stinner <victor.stinner at gmail.com>
date: 2017-08-18T15:18:13+02:00
summary:
bpo-30121: Fix debug assert in subprocess on Windows (#1224)
* bpo-30121: Fix debug assert in subprocess on Windows
This is caused by closing HANDLEs using os.close which is for CRT file
descriptors and not for HANDLEs.
* bpo-30121: Suppress debug assertion in test_subprocess when ran directly
files:
M Lib/subprocess.py
M Lib/test/test_subprocess.py
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 99bca477cec..2805ec3fa37 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -727,7 +727,10 @@ def __init__(self, args, bufsize=-1, executable=None,
to_close.append(self._devnull)
for fd in to_close:
try:
- os.close(fd)
+ if _mswindows and isinstance(fd, Handle):
+ fd.Close()
+ else:
+ os.close(fd)
except OSError:
pass
@@ -1007,6 +1010,9 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
errwrite.Close()
if hasattr(self, '_devnull'):
os.close(self._devnull)
+ # Prevent a double close of these handles/fds from __init__
+ # on error.
+ self._closed_child_pipe_fds = True
# Retain the process handle, but close the thread handle
self._child_created = True
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 1d2d15c7a24..8cda1e81c80 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1116,10 +1116,11 @@ def _test_bufsize_equal_one(self, line, expected, universal_newlines):
p.stdin.write(line) # expect that it flushes the line in text mode
os.close(p.stdin.fileno()) # close it without flushing the buffer
read_line = p.stdout.readline()
- try:
- p.stdin.close()
- except OSError:
- pass
+ with support.SuppressCrashReport():
+ try:
+ p.stdin.close()
+ except OSError:
+ pass
p.stdin = None
self.assertEqual(p.returncode, 0)
self.assertEqual(read_line, expected)
More information about the Python-checkins
mailing list