Kaydet (Commit) 4d385172 authored tarafından Segev Finer's avatar Segev Finer Kaydeden (comit) Victor Stinner

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
üst a7c449b8
...@@ -727,6 +727,9 @@ class Popen(object): ...@@ -727,6 +727,9 @@ class Popen(object):
to_close.append(self._devnull) to_close.append(self._devnull)
for fd in to_close: for fd in to_close:
try: try:
if _mswindows and isinstance(fd, Handle):
fd.Close()
else:
os.close(fd) os.close(fd)
except OSError: except OSError:
pass pass
...@@ -1007,6 +1010,9 @@ class Popen(object): ...@@ -1007,6 +1010,9 @@ class Popen(object):
errwrite.Close() errwrite.Close()
if hasattr(self, '_devnull'): if hasattr(self, '_devnull'):
os.close(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 # Retain the process handle, but close the thread handle
self._child_created = True self._child_created = True
......
...@@ -1116,6 +1116,7 @@ class ProcessTestCase(BaseTestCase): ...@@ -1116,6 +1116,7 @@ class ProcessTestCase(BaseTestCase):
p.stdin.write(line) # expect that it flushes the line in text mode p.stdin.write(line) # expect that it flushes the line in text mode
os.close(p.stdin.fileno()) # close it without flushing the buffer os.close(p.stdin.fileno()) # close it without flushing the buffer
read_line = p.stdout.readline() read_line = p.stdout.readline()
with support.SuppressCrashReport():
try: try:
p.stdin.close() p.stdin.close()
except OSError: except OSError:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment