# HG changeset patch
# User Manuel Jacob <m...@manueljacob.de>
# Date 1594440202 -7200
#      Sat Jul 11 06:03:22 2020 +0200
# Node ID 7bf3570f54114b6298a1b35108c210ca684cc183
# Parent  c49e8aadd06eb715732fcc23713bc9de949381b1
# EXP-Topic stdio
procutil: back out 8403cc54bc83 (make ....procutil.stderr unbuffered)

Changeset 8403cc54bc83 introduced code that opens a second file object
referring to the stderr file descriptor. This broke tests on Windows. The
reason is that on Windows, sys.stderr is buffered and procutil.stderr closed
the file descriptor when it got garbage collected before sys.stderr had the
chance to flush buffered data.

`procutil.stdout` had the same problem for a long time, but we didn’t realize,
as in CI test runs, stdout is not a TTY and in this case no second file object
is opened.

diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -106,18 +106,6 @@
     else:
         stdout = os.fdopen(stdout.fileno(), 'wb', 1)
 
-# stderr should be unbuffered
-if pycompat.ispy3:
-    # On Python 3, buffered streams may expose an underlying raw stream. This 
is
-    # definitively the case for the streams initialized by the interpreter. If
-    # the attribute isn't present, the stream is already unbuffered or doesn't
-    # expose an underlying raw stream, in which case we use the stream as-is.
-    stderr = getattr(stderr, 'raw', stderr)
-elif pycompat.iswindows:
-    # On Windows, stderr is buffered at least when connected to a pipe.
-    stderr = os.fdopen(stderr.fileno(), 'wb', 0)
-# On other platforms, stderr is always unbuffered.
-
 
 findexe = platform.findexe
 _gethgcmd = platform.gethgcmd
diff --git a/tests/test-stdio.py b/tests/test-stdio.py
--- a/tests/test-stdio.py
+++ b/tests/test-stdio.py
@@ -126,18 +126,6 @@
             test_buffering_stdout_ptys_unbuffered
         )
 
-    def test_buffering_stderr_pipes(self):
-        self._test('stderr', _pipes, UNBUFFERED)
-
-    def test_buffering_stderr_ptys(self):
-        self._test('stderr', _ptys, UNBUFFERED)
-
-    def test_buffering_stderr_pipes_unbuffered(self):
-        self._test('stderr', _pipes, UNBUFFERED, python_args=['-u'])
-
-    def test_buffering_stderr_ptys_unbuffered(self):
-        self._test('stderr', _ptys, UNBUFFERED, python_args=['-u'])
-
 
 if __name__ == '__main__':
     import silenttestrunner
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to