bpo-30418: Popen.communicate() always ignore EINVAL (#2002) (#2005) · python/cpython@df04c08 (original) (raw)

Original file line number Diff line number Diff line change
@@ -741,19 +741,21 @@ def _stdin_write(self, input):
741 741 self.stdin.write(input)
742 742 except BrokenPipeError:
743 743 pass # communicate() must ignore broken pipe errors.
744 -except OSError as e:
745 -if e.errno == errno.EINVAL and self.poll() is not None:
746 -# Issue #19612: On Windows, stdin.write() fails with EINVAL
747 -# if the process already exited before the write
744 +except OSError as exc:
745 +if exc.errno == errno.EINVAL:
746 +# bpo-19612, bpo-30418: On Windows, stdin.write() fails
747 +# with EINVAL if the child process exited or if the child
748 +# process is still running but closed the pipe.
748 749 pass
749 750 else:
750 751 raise
752 +
751 753 try:
752 754 self.stdin.close()
753 755 except BrokenPipeError:
754 756 pass # communicate() must ignore broken pipe errors.
755 -except OSError as e:
756 -if e.errno == errno.EINVAL and self.poll() is not None:
757 +except OSError as exc:
758 +if exc.errno == errno.EINVAL:
757 759 pass
758 760 else:
759 761 raise