From: Victor Stinner Date: Fri, 27 Mar 2015 14:20:08 +0000 (+0100) Subject: asyncio: Fix _SelectorTransport.__repr__() if the event loop is closed X-Git-Tag: v3.5.0a3~29^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=79fd962652a60f04ecc7becb116c330063b1706e;p=python asyncio: Fix _SelectorTransport.__repr__() if the event loop is closed --- diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index a38ed1cee3..68e9415e6a 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -535,7 +535,7 @@ class _SelectorTransport(transports._FlowControlMixin, info.append('closing') info.append('fd=%s' % self._sock_fd) # test if the transport was closed - if self._loop is not None: + if self._loop is not None and not self._loop.is_closed(): polling = _test_selector_event(self._loop._selector, self._sock_fd, selectors.EVENT_READ) if polling: diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py index f64e40dafc..9478b95483 100644 --- a/Lib/test/test_asyncio/test_selector_events.py +++ b/Lib/test/test_asyncio/test_selector_events.py @@ -62,6 +62,11 @@ class BaseSelectorEventLoopTests(test_utils.TestCase): self.loop.add_reader._is_coroutine = False transport = self.loop._make_socket_transport(m, asyncio.Protocol()) self.assertIsInstance(transport, _SelectorSocketTransport) + + # Calling repr() must not fail when the event loop is closed + self.loop.close() + repr(transport) + close_transport(transport) @unittest.skipIf(ssl is None, 'No ssl module')