import socket
import warnings
import signal
+import threading
import collections
from . import base_events
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):
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):