From d2af6a6fbe57a4d3bc06fbde6f4c1f4e8ec06dd3 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sun, 19 Jan 2020 17:37:14 -0500 Subject: [PATCH] asyncio: AnyThreadEventLoopPolicy should always use selectors on windows --- tornado/platform/asyncio.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tornado/platform/asyncio.py b/tornado/platform/asyncio.py index 0b79f82ca..a859e7f26 100644 --- a/tornado/platform/asyncio.py +++ b/tornado/platform/asyncio.py @@ -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 -- 2.47.2