issue #477: parent: make iter_read() log disconnect reason.

issue510
David Wilson 6 years ago
parent 81f15028a7
commit ffd46e9f1c

@ -455,20 +455,20 @@ def io_op(func, *args):
signalled by :data:`errno.EPIPE`. signalled by :data:`errno.EPIPE`.
:returns: :returns:
Tuple of `(return_value, disconnected)`, where `return_value` is the Tuple of `(return_value, disconnect_reason)`, where `return_value` is
return value of `func(*args)`, and `disconnected` is :data:`True` if the return value of `func(*args)`, and `disconnected` is an exception
disconnection was detected, otherwise :data:`False`. instance when disconnection was detected, otherwise :data:`None`.
""" """
while True: while True:
try: try:
return func(*args), False return func(*args), None
except (select.error, OSError, IOError): except (select.error, OSError, IOError):
e = sys.exc_info()[1] e = sys.exc_info()[1]
_vv and IOLOG.debug('io_op(%r) -> OSError: %s', func, e) _vv and IOLOG.debug('io_op(%r) -> OSError: %s', func, e)
if e.args[0] == errno.EINTR: if e.args[0] == errno.EINTR:
continue continue
if e.args[0] in (errno.EIO, errno.ECONNRESET, errno.EPIPE): if e.args[0] in (errno.EIO, errno.ECONNRESET, errno.EPIPE):
return None, True return None, e
raise raise

@ -544,7 +544,8 @@ class IteratingRead(object):
for fd in self.poller.poll(self.timeout): for fd in self.poller.poll(self.timeout):
s, disconnected = mitogen.core.io_op(os.read, fd, 4096) s, disconnected = mitogen.core.io_op(os.read, fd, 4096)
if disconnected or not s: if disconnected or not s:
IOLOG.debug('iter_read(%r) -> disconnected', fd) LOG.debug('iter_read(%r) -> disconnected: %s',
fd, disconnected)
self.poller.stop_receive(fd) self.poller.stop_receive(fd)
else: else:
IOLOG.debug('iter_read(%r) -> %r', fd, s) IOLOG.debug('iter_read(%r) -> %r', fd, s)

Loading…
Cancel
Save