# HG changeset patch # User Manuel Jacob # Date 2022-05-31 02:11:34 # Node ID ee4537e365c8ad04f10cfaf058b00f292261b0d5 # Parent c463f45fa114425201085cf5642883fa98e4c44a 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. diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py --- a/mercurial/commandserver.py +++ b/mercurial/commandserver.py @@ -650,12 +650,7 @@ class unixforkingservice: 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 @@ class unixforkingservice: 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 @@ class unixforkingservice: 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()?) diff --git a/mercurial/posix.py b/mercurial/posix.py --- a/mercurial/posix.py +++ b/mercurial/posix.py @@ -716,14 +716,7 @@ def poll(fds): 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, [])))) diff --git a/mercurial/progress.py b/mercurial/progress.py --- a/mercurial/progress.py +++ b/mercurial/progress.py @@ -6,7 +6,6 @@ # GNU General Public License version 2 or any later version. -import errno import threading import time @@ -65,25 +64,6 @@ def fmtremaining(seconds): 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 @@ class progbar: 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() diff --git a/mercurial/worker.py b/mercurial/worker.py --- a/mercurial/worker.py +++ b/mercurial/worker.py @@ -184,20 +184,15 @@ def _posixworker(ui, func, staticargs, a 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 @@ def _posixworker(ui, func, staticargs, a 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()