diff mercurial/utils/procutil.py @ 45148:a37f290a7124

windows: always work around EINVAL in case of broken pipe for stdout / stderr In 29a905fe23ae, I missed the fact that the `winstdout` class works around two unrelated bugs (size limit when writing to consoles and EINVAL in case of broken pipe) and that the latter bug happens even when no console is involved. When writing a test for this, I realized that the same problem applies to stderr, so I applied the workaround for EINVAL to both stdout and stderr. The size limit is worked around in the same case as before (consoles on Windows on Python 2). For that, I changed the `winstdout` class.
author Manuel Jacob <me@manueljacob.de>
date Fri, 17 Jul 2020 03:28:52 +0200
parents a5fa2761a6cd
children fdd54a876213 37c65704869d
line wrap: on
line diff
--- a/mercurial/utils/procutil.py	Fri Jul 17 00:37:33 2020 +0200
+++ b/mercurial/utils/procutil.py	Fri Jul 17 03:28:52 2020 +0200
@@ -119,18 +119,25 @@
     # a silly wrapper to make a bytes stream backed by a unicode one.
     stdin = sys.stdin.buffer
     stdout = _make_write_all(sys.stdout.buffer)
+    stderr = _make_write_all(sys.stderr.buffer)
+    if pycompat.iswindows:
+        # Work around Windows bugs.
+        stdout = platform.winstdout(stdout)
+        stderr = platform.winstdout(stderr)
     if isatty(stdout):
         # The standard library doesn't offer line-buffered binary streams.
         stdout = make_line_buffered(stdout)
-    stderr = _make_write_all(sys.stderr.buffer)
 else:
     # Python 2 uses the I/O streams provided by the C library.
     stdin = sys.stdin
     stdout = sys.stdout
+    stderr = sys.stderr
+    if pycompat.iswindows:
+        # Work around Windows bugs.
+        stdout = platform.winstdout(stdout)
+        stderr = platform.winstdout(stderr)
     if isatty(stdout):
         if pycompat.iswindows:
-            # Work around size limit when writing to console.
-            stdout = platform.winstdout(stdout)
             # The Windows C runtime library doesn't support line buffering.
             stdout = make_line_buffered(stdout)
         else:
@@ -138,7 +145,6 @@
             # replace a TTY destined stdout with a pipe destined stdout (e.g.
             # pager), we want line buffering.
             stdout = os.fdopen(stdout.fileno(), 'wb', 1)
-    stderr = sys.stderr
 
 
 findexe = platform.findexe