Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74895df

Browse files
committed
(Merge 3.4) asyncio: enhance protocol representation
Add "closed" or "closing" to repr() of selector and proactor transports
2 parents cf7ec01 + 0e34dc3 commit 74895df

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

Lib/asyncio/proactor_events.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ def __init__(self, loop, sock, protocol, waiter=None,
4242
self._loop.call_soon(waiter._set_result_unless_cancelled, None)
4343

4444
def __repr__(self):
45-
info = [self.__class__.__name__, 'fd=%s' % self._sock.fileno()]
45+
info = [self.__class__.__name__]
46+
fd = self._sock.fileno()
47+
if fd < 0:
48+
info.append('closed')
49+
elif self._closing:
50+
info.append('closing')
51+
info.append('fd=%s' % fd)
4652
if self._read_fut is not None:
4753
info.append('read=%s' % self._read_fut)
4854
if self._write_fut is not None:

Lib/asyncio/selector_events.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,12 @@ def __init__(self, loop, sock, protocol, extra, server=None):
467467
self._server._attach()
468468

469469
def __repr__(self):
470-
info = [self.__class__.__name__, 'fd=%s' % self._sock_fd]
470+
info = [self.__class__.__name__]
471+
if self._sock is None:
472+
info.append('closed')
473+
elif self._closing:
474+
info.append('closing')
475+
info.append('fd=%s' % self._sock_fd)
471476
# test if the transport was closed
472477
if self._loop is not None:
473478
polling = _test_selector_event(self._loop._selector,

0 commit comments

Comments
 (0)