Issue #19612: subprocess.communicate() now also ignores EINVAL when using at
least two pipes.
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index ce47b5e..f9e9104 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1035,7 +1035,15 @@
                     try:
                         self.stdin.write(input)
                     except IOError as e:
-                        if e.errno != errno.EPIPE:
+                        if e.errno == errno.EPIPE:
+                            # communicate() should ignore broken pipe error
+                            pass
+                        elif (e.errno == errno.EINVAL
+                              and self.poll() is not None):
+                            # Issue #19612: stdin.write() fails with EINVAL
+                            # if the process already exited before the write
+                            pass
+                        else:
                             raise
                 self.stdin.close()
 
diff --git a/Misc/NEWS b/Misc/NEWS
index f2087c5..bdd414e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@
 Library
 -------
 
+- Issue #19612: subprocess.communicate() now also ignores EINVAL when using at
+  least two pipes.
+
 - Fix repr(_socket.socket) on Windows 64-bit: don't fail with OverflowError
   on closed socket.