From: Victor Stinner Date: Thu, 8 Jun 2017 16:20:46 +0000 (+0200) Subject: bpo-30418: Popen.communicate() always ignore EINVAL (#2002) (#2005) X-Git-Tag: v3.5.4rc1~102 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=df04c088493bdbc2defea5e225a94e9bdd8e759f;p=thirdparty%2FPython%2Fcpython.git bpo-30418: Popen.communicate() always ignore EINVAL (#2002) (#2005) 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) --- diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 281ea8af9225..614de40e5cae 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -741,19 +741,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 diff --git a/Misc/NEWS b/Misc/NEWS index 997058b34a55..78ec9f0ccae6 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -56,6 +56,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-30378: Fix the problem that logging.handlers.SysLogHandler cannot handle IPv6 addresses.