From: Ben Darnell Date: Wed, 8 Feb 2023 20:12:47 +0000 (+0000) Subject: asyncio: Remove obsolete code X-Git-Tag: v6.3.0b1~10^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a706b98bd8842b190c6a3e16e28186adb6d131a1;p=thirdparty%2Ftornado.git asyncio: Remove obsolete code AsyncioLoop.start() used to save, set, and restore the thread-local event loop. This avoided some edge cases in early versions of asyncio; this appears to no longer be necessary since Python 3.7 introduced the get_running_loop() method. Removing this logic improves compatibility with Python 3.12, where it is difficult if not impossible to do the same thing without generating DeprecationWarnings. --- diff --git a/tornado/platform/asyncio.py b/tornado/platform/asyncio.py index d839e87d6..a3fbdc37e 100644 --- a/tornado/platform/asyncio.py +++ b/tornado/platform/asyncio.py @@ -74,19 +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 @@ -205,15 +192,7 @@ class BaseAsyncIOLoop(IOLoop): 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()