Skip to content

[3.8] bpo-34679: Restore instantiation Windows IOCP event loop from non-main thread (GH-15492) #15512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Lib/asyncio/proactor_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import socket
import warnings
import signal
import threading
import collections

from . import base_events
Expand Down Expand Up @@ -627,7 +628,9 @@ def __init__(self, proactor):
proactor.set_loop(self)
self._make_self_pipe()
self_no = self._csock.fileno()
signal.set_wakeup_fd(self_no)
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)

def _make_socket_transport(self, sock, protocol, waiter=None,
extra=None, server=None):
Expand Down
19 changes: 19 additions & 0 deletions Lib/test/test_asyncio/test_windows_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ def SIGINT_after_delay():
thread.join()


class ProactorMultithreading(test_utils.TestCase):
def test_run_from_nonmain_thread(self):
finished = False

async def coro():
await asyncio.sleep(0)

def func():
nonlocal finished
loop = asyncio.new_event_loop()
loop.run_until_complete(coro())
finished = True

thread = threading.Thread(target=func)
thread.start()
thread.join()
self.assertTrue(finished)


class ProactorTests(test_utils.TestCase):

def setUp(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restores instantiation of Windows IOCP event loops from the non-main thread.