summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSegev Finer <segev208@gmail.com>2017-08-18 13:18:13 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2017-08-18 13:18:13 (GMT)
commit4d3851727fb82195e4995c6064b0b2d6cbc031c4 (patch)
treed39c125eded8ac59a4108465ff9fbea47c730628 /Lib
parenta7c449b8c08933deabcf329fb74ed1336f6db34f (diff)
downloadcpython-4d3851727fb82195e4995c6064b0b2d6cbc031c4.zip
cpython-4d3851727fb82195e4995c6064b0b2d6cbc031c4.tar.gz
cpython-4d3851727fb82195e4995c6064b0b2d6cbc031c4.tar.bz2
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
Diffstat (limited to 'Lib')
-rw-r--r--Lib/subprocess.py8
-rw-r--r--Lib/test/test_subprocess.py9
2 files changed, 12 insertions, 5 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 99bca47..2805ec3 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -727,7 +727,10 @@ class Popen(object):
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 @@ class Popen(object):
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 1d2d15c..8cda1e8 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1116,10 +1116,11 @@ class ProcessTestCase(BaseTestCase):
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)