From: Ben Darnell Date: Sun, 19 Jan 2020 22:37:14 +0000 (-0500) Subject: asyncio: AnyThreadEventLoopPolicy should always use selectors on windows X-Git-Tag: v6.0.4^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78b4e25ab264ac9e665a85e99b71ea62fd63df17;p=thirdparty%2Ftornado.git asyncio: AnyThreadEventLoopPolicy should always use selectors on windows --- 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