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.
pull/167/head
David Wilson 8 years ago
parent 90791768be
commit 7a061fe18b

@ -170,15 +170,6 @@ def takes_router(func):
return 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): def is_blacklisted_import(importer, fullname):
"""Return ``True`` if `fullname` is part of a blacklisted package, or if """Return ``True`` if `fullname` is part of a blacklisted package, or if
any packages have been whitelisted and `fullname` is not part of one. 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): def io_op(func, *args):
while True:
try: try:
return func(*args), False return func(*args), False
except OSError, e: except OSError, e:
_vv and IOLOG.debug('io_op(%r) -> OSError: %s', func, e) _vv and IOLOG.debug('io_op(%r) -> OSError: %s', func, e)
if e.errno not in (errno.EIO, errno.ECONNRESET, errno.EPIPE): if e.errno == errno.EINTR:
raise continue
if e.errno in (errno.EIO, errno.ECONNRESET, errno.EPIPE):
return None, True return None, True
raise
class PidfulStreamHandler(logging.StreamHandler): class PidfulStreamHandler(logging.StreamHandler):
@ -950,7 +944,7 @@ class Latch(object):
_vv and IOLOG.debug('%r.get() -> sleeping', self) _vv and IOLOG.debug('%r.get() -> sleeping', self)
e = None e = None
try: try:
restart(select.select, [_tls.rsock], [], [], timeout) io_op(select.select, [_tls.rsock], [], [], timeout)
except Exception, e: except Exception, e:
pass pass
@ -1280,7 +1274,7 @@ class Broker(object):
#IOLOG.debug('readers = %r', self._readers) #IOLOG.debug('readers = %r', self._readers)
#IOLOG.debug('writers = %r', self._writers) #IOLOG.debug('writers = %r', self._writers)
rsides, wsides, _ = restart(select.select, (rsides, wsides, _), _ = io_op(select.select,
self._readers, self._readers,
self._writers, self._writers,
(), timeout (), timeout

Loading…
Cancel
Save