Mercurial > public > mercurial-scm > hg
comparison mercurial/utils/procutil.py @ 45077:fa270dcbdb55
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.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Sat, 11 Jul 2020 06:03:22 +0200 |
parents | 9694895749ad |
children | 8628cd1122d2 |
comparison
equal
deleted
inserted
replaced
45076:23119371df5e | 45077:fa270dcbdb55 |
---|---|
103 # On Python 2, Windows doesn't support line buffering. | 103 # On Python 2, Windows doesn't support line buffering. |
104 # Therefore we have a wrapper that implements line buffering. | 104 # Therefore we have a wrapper that implements line buffering. |
105 stdout = make_line_buffered(stdout) | 105 stdout = make_line_buffered(stdout) |
106 else: | 106 else: |
107 stdout = os.fdopen(stdout.fileno(), 'wb', 1) | 107 stdout = os.fdopen(stdout.fileno(), 'wb', 1) |
108 | |
109 # stderr should be unbuffered | |
110 if pycompat.ispy3: | |
111 # On Python 3, buffered streams may expose an underlying raw stream. This is | |
112 # definitively the case for the streams initialized by the interpreter. If | |
113 # the attribute isn't present, the stream is already unbuffered or doesn't | |
114 # expose an underlying raw stream, in which case we use the stream as-is. | |
115 stderr = getattr(stderr, 'raw', stderr) | |
116 elif pycompat.iswindows: | |
117 # On Windows, stderr is buffered at least when connected to a pipe. | |
118 stderr = os.fdopen(stderr.fileno(), 'wb', 0) | |
119 # On other platforms, stderr is always unbuffered. | |
120 | 108 |
121 | 109 |
122 findexe = platform.findexe | 110 findexe = platform.findexe |
123 _gethgcmd = platform.gethgcmd | 111 _gethgcmd = platform.gethgcmd |
124 getuser = platform.getuser | 112 getuser = platform.getuser |