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

Original file line number Diff line number Diff line change
@@ -778,19 +778,21 @@ def _stdin_write(self, input):
778 778 self.stdin.write(input)
779 779 except BrokenPipeError:
780 780 pass # communicate() must ignore broken pipe errors.
781 -except OSError as e:
782 -if e.errno == errno.EINVAL and self.poll() is not None:
783 -# Issue #19612: On Windows, stdin.write() fails with EINVAL
784 -# if the process already exited before the write
781 +except OSError as exc:
782 +if exc.errno == errno.EINVAL:
783 +# bpo-19612, bpo-30418: On Windows, stdin.write() fails
784 +# with EINVAL if the child process exited or if the child
785 +# process is still running but closed the pipe.
785 786 pass
786 787 else:
787 788 raise
789 +
788 790 try:
789 791 self.stdin.close()
790 792 except BrokenPipeError:
791 793 pass # communicate() must ignore broken pipe errors.
792 -except OSError as e:
793 -if e.errno == errno.EINVAL and self.poll() is not None:
794 +except OSError as exc:
795 +if exc.errno == errno.EINVAL:
794 796 pass
795 797 else:
796 798 raise