]> granicus.if.org Git - python/commitdiff
Issue #22922: Fix ProactorEventLoop.close()
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 13 Jan 2015 15:11:19 +0000 (16:11 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 13 Jan 2015 15:11:19 +0000 (16:11 +0100)
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

index 0a4d068554f297f28595d51f5f858df472a007a6..5986e37f6be34029bd16746d99090ebc075a1448 100644 (file)
@@ -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)