]> granicus.if.org Git - python/commitdiff
bpo-30418: Popen.communicate() always ignore EINVAL (#2002) (#2004)
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 8 Jun 2017 21:14:07 +0000 (23:14 +0200)
committerGitHub <noreply@github.com>
Thu, 8 Jun 2017 21:14:07 +0000 (23:14 +0200)
On Windows, subprocess.Popen.communicate() now also ignore EINVAL
on stdin.write() if the child process is still running but closed the
pipe.
(cherry picked from commit d52aa31378ae43e044a300edfe8285954c167216)

Lib/subprocess.py
Misc/NEWS

index 172126929160bfe1442b47beed867d38e8e01341..e626a8afdbb7f07288818416f701d935ef17e5d7 100644 (file)
@@ -776,19 +776,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 b819c6db73af2f637d62c99ec926937e360e8569..d10e7a371f489d95deabe8045efe6723907edab8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -45,6 +45,9 @@ Core and Builtins
 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-29822: inspect.isabstract() now works during __init_subclass__.  Patch
   by Nate Soares.