Mercurial > hg
comparison mercurial/utils/procutil.py @ 45081:29a905fe23ae
procutil: use mercurial.windows.winstdout only on Python 2 and TTYs
Python 3 already works around the bug. The workaround is only needed when
writing to consoles. If stdout is a console, sys.stdout.isatty() is true.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Fri, 10 Jul 2020 10:03:05 +0200 |
parents | 00cdac669614 |
children | b6afe1c52964 |
comparison
equal
deleted
inserted
replaced
45080:00cdac669614 | 45081:29a905fe23ae |
---|---|
89 else: | 89 else: |
90 stdin = sys.stdin | 90 stdin = sys.stdin |
91 stdout = sys.stdout | 91 stdout = sys.stdout |
92 stderr = sys.stderr | 92 stderr = sys.stderr |
93 | 93 |
94 if pycompat.iswindows: | |
95 stdout = platform.winstdout(stdout) | |
96 | |
97 # glibc determines buffering on first write to stdout - if we replace a TTY | 94 # glibc determines buffering on first write to stdout - if we replace a TTY |
98 # destined stdout with a pipe destined stdout (e.g. pager), we want line | 95 # destined stdout with a pipe destined stdout (e.g. pager), we want line |
99 # buffering. | 96 # buffering. |
100 if isatty(stdout): | 97 if isatty(stdout): |
101 if pycompat.ispy3: | 98 if pycompat.ispy3: |
102 # Python 3 implements its own I/O streams. | 99 # Python 3 implements its own I/O streams. |
103 # The standard library doesn't offer line-buffered binary streams. | 100 # The standard library doesn't offer line-buffered binary streams. |
104 stdout = make_line_buffered(stdout) | 101 stdout = make_line_buffered(stdout) |
105 elif pycompat.iswindows: | 102 elif pycompat.iswindows: |
103 # Work around size limit when writing to console. | |
104 stdout = platform.winstdout(stdout) | |
106 # Python 2 uses the I/O streams provided by the C library. | 105 # Python 2 uses the I/O streams provided by the C library. |
107 # The Windows C runtime library doesn't support line buffering. | 106 # The Windows C runtime library doesn't support line buffering. |
108 stdout = make_line_buffered(stdout) | 107 stdout = make_line_buffered(stdout) |
109 else: | 108 else: |
110 stdout = os.fdopen(stdout.fileno(), 'wb', 1) | 109 stdout = os.fdopen(stdout.fileno(), 'wb', 1) |