Mercurial > public > mercurial-scm > hg
comparison mercurial/utils/procutil.py @ 45045:8403cc54bc83
procutil: make mercurial.utils.procutil.stderr unbuffered
For most Mercurial code, it doesn?t make a difference, as the ui object flushes
stderr explicitly (after the change, we could get rid of the explicit flush).
One example where it makes a observable difference is mercurial.util.timed().
Without the patch, the time is not immediately shown on Python 3. With the
patch, it?s shown immediately on all Python versions and platforms.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Sun, 05 Jul 2020 13:09:22 +0200 |
parents | be58fb1eaa73 |
children | 9694895749ad |
comparison
equal
deleted
inserted
replaced
45044:359884685eab | 45045:8403cc54bc83 |
---|---|
96 # On Python 2, Windows doesn't support line buffering. | 96 # On Python 2, Windows doesn't support line buffering. |
97 # Therefore we have a wrapper that implements line buffering. | 97 # Therefore we have a wrapper that implements line buffering. |
98 stdout = make_line_buffered(stdout) | 98 stdout = make_line_buffered(stdout) |
99 else: | 99 else: |
100 stdout = os.fdopen(stdout.fileno(), 'wb', 1) | 100 stdout = os.fdopen(stdout.fileno(), 'wb', 1) |
101 | |
102 # stderr should be unbuffered | |
103 if pycompat.ispy3: | |
104 # On Python 3, buffered streams may expose an underlying raw stream. This is | |
105 # definitively the case for the streams initialized by the interpreter. If | |
106 # the attribute isn't present, the stream is already unbuffered or doesn't | |
107 # expose an underlying raw stream, in which case we use the stream as-is. | |
108 stderr = getattr(stderr, 'raw', stderr) | |
109 elif pycompat.iswindows: | |
110 # On Windows, stderr is buffered at least when connected to a pipe. | |
111 stderr = os.fdopen(stderr.fileno(), 'wb', 0) | |
112 # On other platforms, stderr is always unbuffered. | |
101 | 113 |
102 | 114 |
103 findexe = platform.findexe | 115 findexe = platform.findexe |
104 _gethgcmd = platform.gethgcmd | 116 _gethgcmd = platform.gethgcmd |
105 getuser = platform.getuser | 117 getuser = platform.getuser |