comparison mercurial/progress.py @ 49302:ee4537e365c8

py3: remove retry on EINTR errno Since the implementation of PEP 475 (Python 3.5), Python retries system calls failing with EINTR. Therefore we don’t need the logic that retries it in Python code.
author Manuel Jacob <me@manueljacob.de>
date Tue, 31 May 2022 04:11:34 +0200
parents 642e31cb55f0
children
comparison
equal deleted inserted replaced
49301:c463f45fa114 49302:ee4537e365c8
4 # 4 #
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 8
9 import errno
10 import threading 9 import threading
11 import time 10 import time
12 11
13 from .i18n import _ 12 from .i18n import _
14 from . import encoding 13 from . import encoding
61 weeks += 1 60 weeks += 1
62 years = weeks // 52 61 years = weeks // 52
63 weeks -= years * 52 62 weeks -= years * 52
64 # i18n: format X years and YY weeks as "XyYYw" 63 # i18n: format X years and YY weeks as "XyYYw"
65 return _(b"%dy%02dw") % (years, weeks) 64 return _(b"%dy%02dw") % (years, weeks)
66
67
68 # file_write() and file_flush() of Python 2 do not restart on EINTR if
69 # the file is attached to a "slow" device (e.g. a terminal) and raise
70 # IOError. We cannot know how many bytes would be written by file_write(),
71 # but a progress text is known to be short enough to be written by a
72 # single write() syscall, so we can just retry file_write() with the whole
73 # text. (issue5532)
74 #
75 # This should be a short-term workaround. We'll need to fix every occurrence
76 # of write() to a terminal or pipe.
77 def _eintrretry(func, *args):
78 while True:
79 try:
80 return func(*args)
81 except IOError as err:
82 if err.errno == errno.EINTR:
83 continue
84 raise
85 65
86 66
87 class progbar: 67 class progbar:
88 def __init__(self, ui): 68 def __init__(self, ui):
89 self.ui = ui 69 self.ui = ui
205 else: 185 else:
206 self._writeerr(b'\n') 186 self._writeerr(b'\n')
207 self._flusherr() 187 self._flusherr()
208 188
209 def _flusherr(self): 189 def _flusherr(self):
210 _eintrretry(self.ui.ferr.flush) 190 self.ui.ferr.flush()
211 191
212 def _writeerr(self, msg): 192 def _writeerr(self, msg):
213 _eintrretry(self.ui.ferr.write, msg) 193 self.ui.ferr.write(msg)
214 194
215 def width(self): 195 def width(self):
216 tw = self.ui.termwidth() 196 tw = self.ui.termwidth()
217 return min(int(self.ui.config(b'progress', b'width', default=tw)), tw) 197 return min(int(self.ui.config(b'progress', b'width', default=tw)), tw)
218 198