From b86a96802bf7e054b7b219ee7e9c8fa2444f94d6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 13 Jan 2015 16:11:19 +0100 Subject: [PATCH 1/2] Issue #22922: Fix ProactorEventLoop.close() Close the IocpProactor before closing the event loop. IocpProactor.close() can call loop.call_soon(), which is forbidden when the event loop is closed. --- Lib/asyncio/proactor_events.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py index 0a4d068554f..5986e37f6be 100644 --- a/Lib/asyncio/proactor_events.py +++ b/Lib/asyncio/proactor_events.py @@ -387,13 +387,19 @@ class BaseProactorEventLoop(base_events.BaseEventLoop): raise RuntimeError("Cannot close a running event loop") if self.is_closed(): return + + # Call these methods before closing the event loop (before calling + # BaseEventLoop.close), because they can schedule callbacks with + # call_soon(), which is forbidden when the event loop is closed. self._stop_accept_futures() self._close_self_pipe() - super().close() self._proactor.close() self._proactor = None self._selector = None + # Close the event loop + super().close() + def sock_recv(self, sock, n): return self._proactor.recv(sock, n) From 9036e49ba1acdd49ed7aa86a228a2657ca72c336 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 13 Jan 2015 16:13:06 +0100 Subject: [PATCH 2/2] Tulip issue 184: Fix test_pipe() on Windows Pass explicitly the event loop to StreamReaderProtocol. --- Lib/test/test_asyncio/test_windows_events.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py index 9b264a64b0a..f9b3dd1567b 100644 --- a/Lib/test/test_asyncio/test_windows_events.py +++ b/Lib/test/test_asyncio/test_windows_events.py @@ -67,7 +67,8 @@ class ProactorTests(test_utils.TestCase): clients = [] for i in range(5): stream_reader = asyncio.StreamReader(loop=self.loop) - protocol = asyncio.StreamReaderProtocol(stream_reader) + protocol = asyncio.StreamReaderProtocol(stream_reader, + loop=self.loop) trans, proto = yield from self.loop.create_pipe_connection( lambda: protocol, ADDRESS) self.assertIsInstance(trans, asyncio.Transport)