Read about our upcoming Code of Conduct on this issue

Commit d94e1e85 authored by Manuel Jacob's avatar Manuel Jacob
Browse files

procutil: make stdout line-buffered on Windows if connected to TTY

Windows doesn’t support line buffering. Previously, we worked around that by
setting the stream unbuffered. Instead, we can use our own line buffering we
already use on Python 3.
parent c88577199023
......@@ -84,23 +84,21 @@ stderr = pycompat.stderr
stdin = pycompat.stdin
stdout = pycompat.stdout
if pycompat.iswindows:
stdout = platform.winstdout(stdout)
# glibc determines buffering on first write to stdout - if we replace a TTY
# destined stdout with a pipe destined stdout (e.g. pager), we want line
# buffering (or unbuffered, on Windows)
# buffering.
if isatty(stdout):
if pycompat.iswindows:
# Windows doesn't support line buffering
stdout = os.fdopen(stdout.fileno(), 'wb', 0)
elif pycompat.ispy3:
if pycompat.ispy3 or pycompat.iswindows:
# On Python 3, buffered binary streams can't be set line-buffered.
# On Python 2, Windows doesn't support line buffering.
# Therefore we have a wrapper that implements line buffering.
stdout = make_line_buffered(stdout)
stdout = os.fdopen(stdout.fileno(), 'wb', 1)
if pycompat.iswindows:
stdout = platform.winstdout(stdout)
findexe = platform.findexe
_gethgcmd = platform.gethgcmd
......@@ -89,7 +89,6 @@ class TestStdout(unittest.TestCase):
def test_stdout_ptys_unbuffered(self):
self._test(_ptys, UNBUFFERED, python_args=['-u'])
# On Windows, test_stdout_ptys wouldn't pass, but it's skipped anyway.
if not pycompat.ispy3 and not pycompat.iswindows:
# On Python 2 on non-Windows, we manually open stdout in line-buffered
# mode if connected to a TTY. We should check if Python was configured
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment