[Python-checkins] cpython (3.4): asyncio: Fix _SelectorTransport.__repr__() if the event loop is closed

victor.stinner python-checkins at python.org
Fri Mar 27 15:21:58 CET 2015


https://hg.python.org/cpython/rev/e08108d5488e
changeset:   95216:e08108d5488e
branch:      3.4
parent:      95205:9be2405385ec
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Fri Mar 27 15:20:08 2015 +0100
summary:
  asyncio: Fix _SelectorTransport.__repr__() if the event loop is closed

files:
  Lib/asyncio/selector_events.py                |  2 +-
  Lib/test/test_asyncio/test_selector_events.py |  5 +++++
  2 files changed, 6 insertions(+), 1 deletions(-)


diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -535,7 +535,7 @@
             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
--- a/Lib/test/test_asyncio/test_selector_events.py
+++ b/Lib/test/test_asyncio/test_selector_events.py
@@ -62,6 +62,11 @@
         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')

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list