Commit 7a061fe1 authored by David Wilson's avatar David Wilson

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.
parent 90791768
...@@ -170,15 +170,6 @@ def takes_router(func): ...@@ -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): ...@@ -208,13 +199,16 @@ def set_block(fd):
def io_op(func, *args): def io_op(func, *args):
try: while True:
return func(*args), False try:
except OSError, e: return func(*args), False
_vv and IOLOG.debug('io_op(%r) -> OSError: %s', func, e) except OSError, e:
if e.errno not in (errno.EIO, errno.ECONNRESET, errno.EPIPE): _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 raise
return None, True
class PidfulStreamHandler(logging.StreamHandler): class PidfulStreamHandler(logging.StreamHandler):
...@@ -950,7 +944,7 @@ class Latch(object): ...@@ -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): ...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment