From: Victor Stinner Date: Sun, 12 Oct 2014 07:52:11 +0000 (+0200) Subject: asyncio: enhance protocol representation X-Git-Tag: v3.5.0a1~686^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e34dc37379e3c42b19c30410e190966e65f4dad;p=python asyncio: enhance protocol representation Add "closed" or "closing" to repr() of selector and proactor transports --- diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py index 0ad0656418..7132300a56 100644 --- a/Lib/asyncio/proactor_events.py +++ b/Lib/asyncio/proactor_events.py @@ -42,7 +42,13 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin, self._loop.call_soon(waiter._set_result_unless_cancelled, None) def __repr__(self): - info = [self.__class__.__name__, 'fd=%s' % self._sock.fileno()] + info = [self.__class__.__name__] + fd = self._sock.fileno() + if fd < 0: + info.append('closed') + elif self._closing: + info.append('closing') + info.append('fd=%s' % fd) if self._read_fut is not None: info.append('read=%s' % self._read_fut) if self._write_fut is not None: diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 33de92e1e4..a55eff7876 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -467,7 +467,12 @@ class _SelectorTransport(transports._FlowControlMixin, self._server._attach() def __repr__(self): - info = [self.__class__.__name__, 'fd=%s' % self._sock_fd] + info = [self.__class__.__name__] + if self._sock is None: + info.append('closed') + elif self._closing: + info.append('closing') + info.append('fd=%s' % self._sock_fd) # test if the transport was closed if self._loop is not None: polling = _test_selector_event(self._loop._selector,