]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-30418: Popen.communicate() always ignore EINVAL (#2002)
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 8 Jun 2017 15:30:39 +0000 (17:30 +0200)
committerGitHub <noreply@github.com>
Thu, 8 Jun 2017 15:30:39 +0000 (17:30 +0200)
On Windows, subprocess.Popen.communicate() now also ignore EINVAL
on stdin.write() if the child process is still running but closed the
pipe.

Lib/subprocess.py
Misc/NEWS

index 551aad342b8304f3f956563d7381919c064de321..32417584528e0b6ffd5be0e18315ed3237139a98 100644 (file)
@@ -778,19 +778,21 @@ class Popen(object):
                 self.stdin.write(input)
             except BrokenPipeError:
                 pass  # communicate() must ignore broken pipe errors.
-            except OSError as e:
-                if e.errno == errno.EINVAL and self.poll() is not None:
-                    # Issue #19612: On Windows, stdin.write() fails with EINVAL
-                    # if the process already exited before the write
+            except OSError as exc:
+                if exc.errno == errno.EINVAL:
+                    # bpo-19612, bpo-30418: On Windows, stdin.write() fails
+                    # with EINVAL if the child process exited or if the child
+                    # process is still running but closed the pipe.
                     pass
                 else:
                     raise
+
         try:
             self.stdin.close()
         except BrokenPipeError:
             pass  # communicate() must ignore broken pipe errors.
-        except OSError as e:
-            if e.errno == errno.EINVAL and self.poll() is not None:
+        except OSError as exc:
+            if exc.errno == errno.EINVAL:
                 pass
             else:
                 raise
index 29c0005638d6c3babc7a44561c712b1e1993afac..7d31839e6734d8aaf58020e8c2af8f1c31f1206b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -350,6 +350,9 @@ Extension Modules
 Library
 -------
 
+- bpo-30418: On Windows, subprocess.Popen.communicate() now also ignore EINVAL
+  on stdin.write() if the child process is still running but closed the pipe.
+
 - bpo-30463: Addded empty __slots__ to abc.ABC.  This allows subclassers
   to deny __dict__ and __weakref__ creation.  Patch by Aaron Hall.