]> granicus.if.org Git - python/commitdiff
bpo-34679: ProactorEventLoop only uses set_wakeup_fd() in main thread (GH-16901)
authorVictor Stinner <vstinner@python.org>
Wed, 23 Oct 2019 15:25:29 +0000 (17:25 +0200)
committerGitHub <noreply@github.com>
Wed, 23 Oct 2019 15:25:29 +0000 (17:25 +0200)
bpo-34679, bpo-38563: asyncio.ProactorEventLoop.close() now only calls
signal.set_wakeup_fd() in the main thread.

Lib/asyncio/proactor_events.py
Lib/test/test_asyncio/test_windows_events.py
Misc/NEWS.d/next/Library/2019-10-23-16-25-12.bpo-34679.Bnw8o3.rst [new file with mode: 0644]

index 229f56e6bb9e29c47f4b5a41c939324e40055fdf..830d8edc32f90a1538bbf10c4bf2f0881b17e51f 100644 (file)
@@ -627,10 +627,9 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
         self._accept_futures = {}   # socket file descriptor => Future
         proactor.set_loop(self)
         self._make_self_pipe()
-        self_no = self._csock.fileno()
         if threading.current_thread() is threading.main_thread():
             # wakeup fd can only be installed to a file descriptor from the main thread
-            signal.set_wakeup_fd(self_no)
+            signal.set_wakeup_fd(self._csock.fileno())
 
     def _make_socket_transport(self, sock, protocol, waiter=None,
                                extra=None, server=None):
@@ -676,7 +675,8 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
         if self.is_closed():
             return
 
-        signal.set_wakeup_fd(-1)
+        if threading.current_thread() is threading.main_thread():
+            signal.set_wakeup_fd(-1)
         # 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.
index 9ed10fc20f8170305a0566465684461ab81d1ce9..6b005702c9be73465283d56fa9d9eadc36e954d3 100644 (file)
@@ -69,6 +69,8 @@ class ProactorMultithreading(test_utils.TestCase):
             nonlocal finished
             loop = asyncio.new_event_loop()
             loop.run_until_complete(coro())
+            # close() must not call signal.set_wakeup_fd()
+            loop.close()
             finished = True
 
         thread = threading.Thread(target=func)
diff --git a/Misc/NEWS.d/next/Library/2019-10-23-16-25-12.bpo-34679.Bnw8o3.rst b/Misc/NEWS.d/next/Library/2019-10-23-16-25-12.bpo-34679.Bnw8o3.rst
new file mode 100644 (file)
index 0000000..34334db
--- /dev/null
@@ -0,0 +1,2 @@
+asynci.ProactorEventLoop.close() now only calls signal.set_wakeup_fd() in the
+main thread.