From 61ca12a78c033a92359815116767030a3de2874f Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Wed, 15 Jun 2022 15:02:48 +0100 Subject: [PATCH 1/2] no longer call set_event_loop in IOLoop.start() --- tornado/platform/asyncio.py | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/tornado/platform/asyncio.py b/tornado/platform/asyncio.py index 58d31ddd81..67c45d239f 100644 --- a/tornado/platform/asyncio.py +++ b/tornado/platform/asyncio.py @@ -74,21 +74,6 @@ def _atexit_callback() -> None: atexit.register(_atexit_callback) -if sys.version_info >= (3, 10): - - def _get_event_loop() -> asyncio.AbstractEventLoop: - try: - return asyncio.get_running_loop() - except RuntimeError: - pass - - return asyncio.get_event_loop_policy().get_event_loop() - - -else: - from asyncio import get_event_loop as _get_event_loop - - class BaseAsyncIOLoop(IOLoop): def initialize( # type: ignore self, asyncio_loop: asyncio.AbstractEventLoop, **kwargs: Any @@ -207,15 +192,7 @@ def _handle_events(self, fd: int, events: int) -> None: handler_func(fileobj, events) def start(self) -> None: - try: - old_loop = _get_event_loop() - except (RuntimeError, AssertionError): - old_loop = None # type: ignore - try: - asyncio.set_event_loop(self.asyncio_loop) - self.asyncio_loop.run_forever() - finally: - asyncio.set_event_loop(old_loop) + self.asyncio_loop.run_forever() def stop(self) -> None: self.asyncio_loop.stop() From 00aa1cfc869eefc32ed0354e7e346cc2771bc971 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Wed, 15 Jun 2022 15:09:43 +0100 Subject: [PATCH 2/2] Update tornado/platform/asyncio.py --- tornado/platform/asyncio.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tornado/platform/asyncio.py b/tornado/platform/asyncio.py index 67c45d239f..838055a7f5 100644 --- a/tornado/platform/asyncio.py +++ b/tornado/platform/asyncio.py @@ -74,6 +74,7 @@ def _atexit_callback() -> None: atexit.register(_atexit_callback) + class BaseAsyncIOLoop(IOLoop): def initialize( # type: ignore self, asyncio_loop: asyncio.AbstractEventLoop, **kwargs: Any