comparison mercurial/utils/procutil.py @ 45043:be58fb1eaa73

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.
author Manuel Jacob <me@manueljacob.de>
date Sat, 04 Jul 2020 11:41:39 +0200
parents c88577199023
children 8403cc54bc83
comparison
equal deleted inserted replaced
45042:c88577199023 45043:be58fb1eaa73
82 82
83 stderr = pycompat.stderr 83 stderr = pycompat.stderr
84 stdin = pycompat.stdin 84 stdin = pycompat.stdin
85 stdout = pycompat.stdout 85 stdout = pycompat.stdout
86 86
87 if pycompat.iswindows:
88 stdout = platform.winstdout(stdout)
89
87 # glibc determines buffering on first write to stdout - if we replace a TTY 90 # glibc determines buffering on first write to stdout - if we replace a TTY
88 # destined stdout with a pipe destined stdout (e.g. pager), we want line 91 # destined stdout with a pipe destined stdout (e.g. pager), we want line
89 # buffering (or unbuffered, on Windows) 92 # buffering.
90 if isatty(stdout): 93 if isatty(stdout):
91 if pycompat.iswindows: 94 if pycompat.ispy3 or pycompat.iswindows:
92 # Windows doesn't support line buffering
93 stdout = os.fdopen(stdout.fileno(), 'wb', 0)
94 elif pycompat.ispy3:
95 # On Python 3, buffered binary streams can't be set line-buffered. 95 # On Python 3, buffered binary streams can't be set line-buffered.
96 # On Python 2, Windows doesn't support line buffering.
96 # Therefore we have a wrapper that implements line buffering. 97 # Therefore we have a wrapper that implements line buffering.
97 stdout = make_line_buffered(stdout) 98 stdout = make_line_buffered(stdout)
98 else: 99 else:
99 stdout = os.fdopen(stdout.fileno(), 'wb', 1) 100 stdout = os.fdopen(stdout.fileno(), 'wb', 1)
100
101 if pycompat.iswindows:
102 stdout = platform.winstdout(stdout)
103 101
104 102
105 findexe = platform.findexe 103 findexe = platform.findexe
106 _gethgcmd = platform.gethgcmd 104 _gethgcmd = platform.gethgcmd
107 getuser = platform.getuser 105 getuser = platform.getuser