]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
asyncio: AnyThreadEventLoopPolicy should always use selectors on windows 2799/head
authorBen Darnell <ben@bendarnell.com>
Sun, 19 Jan 2020 22:37:14 +0000 (17:37 -0500)
committerBen Darnell <ben@bendarnell.com>
Sun, 19 Jan 2020 22:37:14 +0000 (17:37 -0500)
tornado/platform/asyncio.py

index 0b79f82ca8ff6e3b75a8b85fa08b09695647a8b5..a859e7f262330568bfb4c1c319382aa85562ae91 100644 (file)
@@ -21,6 +21,7 @@ the same event loop.
 
 import concurrent.futures
 import functools
+import sys
 
 from threading import get_ident
 from tornado.gen import convert_yielded
@@ -307,7 +308,15 @@ def to_asyncio_future(tornado_future: asyncio.Future) -> asyncio.Future:
     return convert_yielded(tornado_future)
 
 
-class AnyThreadEventLoopPolicy(asyncio.DefaultEventLoopPolicy):  # type: ignore
+if sys.platform == "win32" and hasattr(asyncio, "WindowsSelectorEventLoopPolicy"):
+    # "Any thread" and "selector" should be orthogonal, but there's not a clean
+    # interface for composing policies so pick the right base.
+    _BasePolicy = asyncio.WindowsSelectorEventLoopPolicy  # type: ignore
+else:
+    _BasePolicy = asyncio.DefaultEventLoopPolicy
+
+
+class AnyThreadEventLoopPolicy(_BasePolicy):  # type: ignore
     """Event loop policy that allows loop creation on any thread.
 
     The default `asyncio` event loop policy only automatically creates