]> granicus.if.org Git - python/commitdiff
bpo-30121: Fix debug assert in subprocess on Windows (#1224)
authorSegev Finer <segev208@gmail.com>
Fri, 18 Aug 2017 13:18:13 +0000 (16:18 +0300)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 18 Aug 2017 13:18:13 +0000 (15:18 +0200)
* 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

Lib/subprocess.py
Lib/test/test_subprocess.py

index 99bca477cecdab1814727ec15d77dbb08d11b4f1..2805ec3fa3749df396991ae9b5662f42ea029def 100644 (file)
@@ -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
index 1d2d15c7a24c3b150f003641b9115aa1f2c0a9e8..8cda1e81c8059b7b8d272cfe46ef4ff006be9fd4 100644 (file)
@@ -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)