Mercurial > public > mercurial-scm > hg
comparison mercurial/windows.py @ 45148:a37f290a7124
windows: always work around EINVAL in case of broken pipe for stdout / stderr
In 29a905fe23ae, I missed the fact that the `winstdout` class works around two
unrelated bugs (size limit when writing to consoles and EINVAL in case of
broken pipe) and that the latter bug happens even when no console is involved.
When writing a test for this, I realized that the same problem applies to
stderr, so I applied the workaround for EINVAL to both stdout and stderr.
The size limit is worked around in the same case as before (consoles on Windows
on Python 2). For that, I changed the `winstdout` class.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Fri, 17 Jul 2020 03:28:52 +0200 |
parents | aea246bc04bd |
children | 74b486226480 |
comparison
equal
deleted
inserted
replaced
45147:c2c862b9b544 | 45148:a37f290a7124 |
---|---|
195 error may happen. Python 3 already works around that. | 195 error may happen. Python 3 already works around that. |
196 ''' | 196 ''' |
197 | 197 |
198 def __init__(self, fp): | 198 def __init__(self, fp): |
199 self.fp = fp | 199 self.fp = fp |
200 self.throttle = not pycompat.ispy3 and fp.isatty() | |
200 | 201 |
201 def __getattr__(self, key): | 202 def __getattr__(self, key): |
202 return getattr(self.fp, key) | 203 return getattr(self.fp, key) |
203 | 204 |
204 def close(self): | 205 def close(self): |
206 self.fp.close() | 207 self.fp.close() |
207 except IOError: | 208 except IOError: |
208 pass | 209 pass |
209 | 210 |
210 def write(self, s): | 211 def write(self, s): |
212 if not pycompat.ispy3: | |
213 self.softspace = 0 | |
211 try: | 214 try: |
215 if not self.throttle: | |
216 return self.fp.write(s) | |
212 # This is workaround for "Not enough space" error on | 217 # This is workaround for "Not enough space" error on |
213 # writing large size of data to console. | 218 # writing large size of data to console. |
214 limit = 16000 | 219 limit = 16000 |
215 l = len(s) | 220 l = len(s) |
216 start = 0 | 221 start = 0 |
217 self.softspace = 0 | |
218 while start < l: | 222 while start < l: |
219 end = start + limit | 223 end = start + limit |
220 self.fp.write(s[start:end]) | 224 self.fp.write(s[start:end]) |
221 start = end | 225 start = end |
222 except IOError as inst: | 226 except IOError as inst: |