Mercurial > hg
changeset 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 | c463f45fa114 |
children | dfdf85f37215 |
files | mercurial/commandserver.py mercurial/posix.py mercurial/progress.py mercurial/worker.py |
diffstat | 4 files changed, 14 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commandserver.py Tue May 31 03:39:42 2022 +0200 +++ b/mercurial/commandserver.py Tue May 31 04:11:34 2022 +0200 @@ -650,12 +650,7 @@ def _acceptnewconnection(self, sock, selector): h = self._servicehandler - try: - conn, _addr = sock.accept() - except socket.error as inst: - if inst.args[0] == errno.EINTR: - return - raise + conn, _addr = sock.accept() # Future improvement: On Python 3.7, maybe gc.freeze() can be used # to prevent COW memory from being touched by GC. @@ -688,12 +683,7 @@ def _handlemainipc(self, sock, selector): """Process messages sent from a worker""" - try: - path = sock.recv(32768) # large enough to receive path - except socket.error as inst: - if inst.args[0] == errno.EINTR: - return - raise + path = sock.recv(32768) # large enough to receive path self._repoloader.load(path) def _sigchldhandler(self, signal, frame): @@ -704,8 +694,6 @@ try: pid, _status = os.waitpid(-1, options) except OSError as inst: - if inst.errno == errno.EINTR: - continue if inst.errno != errno.ECHILD: raise # no child processes at all (reaped by other waitpid()?)
--- a/mercurial/posix.py Tue May 31 03:39:42 2022 +0200 +++ b/mercurial/posix.py Tue May 31 04:11:34 2022 +0200 @@ -716,14 +716,7 @@ In unsupported cases, it will raise a NotImplementedError""" try: - while True: - try: - res = select.select(fds, fds, fds) - break - except select.error as inst: - if inst.args[0] == errno.EINTR: - continue - raise + res = select.select(fds, fds, fds) except ValueError: # out of range file descriptor raise NotImplementedError() return sorted(list(set(sum(res, []))))
--- a/mercurial/progress.py Tue May 31 03:39:42 2022 +0200 +++ b/mercurial/progress.py Tue May 31 04:11:34 2022 +0200 @@ -6,7 +6,6 @@ # GNU General Public License version 2 or any later version. -import errno import threading import time @@ -65,25 +64,6 @@ return _(b"%dy%02dw") % (years, weeks) -# file_write() and file_flush() of Python 2 do not restart on EINTR if -# the file is attached to a "slow" device (e.g. a terminal) and raise -# IOError. We cannot know how many bytes would be written by file_write(), -# but a progress text is known to be short enough to be written by a -# single write() syscall, so we can just retry file_write() with the whole -# text. (issue5532) -# -# This should be a short-term workaround. We'll need to fix every occurrence -# of write() to a terminal or pipe. -def _eintrretry(func, *args): - while True: - try: - return func(*args) - except IOError as err: - if err.errno == errno.EINTR: - continue - raise - - class progbar: def __init__(self, ui): self.ui = ui @@ -207,10 +187,10 @@ self._flusherr() def _flusherr(self): - _eintrretry(self.ui.ferr.flush) + self.ui.ferr.flush() def _writeerr(self, msg): - _eintrretry(self.ui.ferr.write, msg) + self.ui.ferr.write(msg) def width(self): tw = self.ui.termwidth()
--- a/mercurial/worker.py Tue May 31 03:39:42 2022 +0200 +++ b/mercurial/worker.py Tue May 31 04:11:34 2022 +0200 @@ -184,20 +184,15 @@ def waitforworkers(blocking=True): for pid in pids.copy(): p = st = 0 - while True: - try: - p, st = os.waitpid(pid, (0 if blocking else os.WNOHANG)) - break - except OSError as e: - if e.errno == errno.EINTR: - continue - elif e.errno == errno.ECHILD: - # child would already be reaped, but pids yet been - # updated (maybe interrupted just after waitpid) - pids.discard(pid) - break - else: - raise + try: + p, st = os.waitpid(pid, (0 if blocking else os.WNOHANG)) + except OSError as e: + if e.errno == errno.ECHILD: + # child would already be reaped, but pids yet been + # updated (maybe interrupted just after waitpid) + pids.discard(pid) + else: + raise if not p: # skip subsequent steps, because child process should # be still running in this case @@ -302,10 +297,6 @@ key.fileobj.close() # pytype: enable=attribute-error openpipes -= 1 - except IOError as e: - if e.errno == errno.EINTR: - continue - raise except: # re-raises killworkers() cleanup()