]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
asyncio: Remove obsolete code
authorBen Darnell <ben@bendarnell.com>
Wed, 8 Feb 2023 20:12:47 +0000 (20:12 +0000)
committerBen Darnell <ben@bendarnell.com>
Wed, 8 Feb 2023 21:13:12 +0000 (21:13 +0000)
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.

tornado/platform/asyncio.py

index d839e87d6a2c3597b9f69a0bfab719b166ae15b4..a3fbdc37e39deaf63c86dda11fe13f2f5aca33a8 100644 (file)
@@ -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()