From 7a061fe18b0cdaa9a1c79db0a60afd514318ef21 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 24 Mar 2018 17:16:32 +0545 Subject: [PATCH] core: merge restart() into io_op() Any long-running system call may suffer EINTR, so arrange for all IO calls to be wrapped in the restart loop. --- mitogen/core.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/mitogen/core.py b/mitogen/core.py index cd37a8ff..924b6907 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -170,15 +170,6 @@ def takes_router(func): return func -def restart(func, *args): - while True: - try: - return func(*args) - except (select.error, OSError), e: - if e[0] != errno.EINTR: - raise - - def is_blacklisted_import(importer, fullname): """Return ``True`` if `fullname` is part of a blacklisted package, or if any packages have been whitelisted and `fullname` is not part of one. @@ -208,13 +199,16 @@ def set_block(fd): def io_op(func, *args): - try: - return func(*args), False - except OSError, e: - _vv and IOLOG.debug('io_op(%r) -> OSError: %s', func, e) - if e.errno not in (errno.EIO, errno.ECONNRESET, errno.EPIPE): + while True: + try: + return func(*args), False + except OSError, e: + _vv and IOLOG.debug('io_op(%r) -> OSError: %s', func, e) + if e.errno == errno.EINTR: + continue + if e.errno in (errno.EIO, errno.ECONNRESET, errno.EPIPE): + return None, True raise - return None, True class PidfulStreamHandler(logging.StreamHandler): @@ -950,7 +944,7 @@ class Latch(object): _vv and IOLOG.debug('%r.get() -> sleeping', self) e = None try: - restart(select.select, [_tls.rsock], [], [], timeout) + io_op(select.select, [_tls.rsock], [], [], timeout) except Exception, e: pass @@ -1280,7 +1274,7 @@ class Broker(object): #IOLOG.debug('readers = %r', self._readers) #IOLOG.debug('writers = %r', self._writers) - rsides, wsides, _ = restart(select.select, + (rsides, wsides, _), _ = io_op(select.select, self._readers, self._writers, (), timeout