]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
asyncio: Avoid deprecation warning in start on py310
authorBen Darnell <ben@bendarnell.com>
Tue, 28 Dec 2021 19:52:52 +0000 (14:52 -0500)
committerBen Darnell <ben@bendarnell.com>
Sun, 16 Jan 2022 21:49:19 +0000 (16:49 -0500)
Also avoid deprecated asyncio.get_event_loop in asyncio_test.

tornado/platform/asyncio.py
tornado/test/asyncio_test.py

index a983384ff2978d16cdb94408ea640586d61c0558..a244777a3772826414ef8ec1ab6a3aee34a2cd32 100644 (file)
@@ -191,7 +191,9 @@ class BaseAsyncIOLoop(IOLoop):
 
     def start(self) -> None:
         try:
-            old_loop = asyncio.get_event_loop()
+            with warnings.catch_warnings():
+                warnings.simplefilter("ignore", DeprecationWarning)
+                old_loop = asyncio.get_event_loop()
         except (RuntimeError, AssertionError):
             old_loop = None  # type: ignore
         try:
index e4db2995b7124eb4600f80ce3e3013657ef8a683..a6d36ff272025da6cd1f97e1e4766dac72f91bd8 100644 (file)
@@ -32,7 +32,10 @@ class AsyncIOLoopTest(AsyncTestCase):
 
     def test_asyncio_callback(self):
         # Basic test that the asyncio loop is set up correctly.
-        asyncio.get_event_loop().call_soon(self.stop)
+        async def add_callback():
+            asyncio.get_event_loop().call_soon(self.stop)
+
+        self.asyncio_loop.run_until_complete(add_callback())
         self.wait()
 
     @gen_test
@@ -90,21 +93,15 @@ class AsyncIOLoopTest(AsyncTestCase):
         # Asyncio only supports coroutines that yield asyncio-compatible
         # Futures (which our Future is since 5.0).
         self.assertEqual(
-            asyncio.get_event_loop().run_until_complete(
-                native_coroutine_without_adapter()
-            ),
+            self.asyncio_loop.run_until_complete(native_coroutine_without_adapter()),
             42,
         )
         self.assertEqual(
-            asyncio.get_event_loop().run_until_complete(
-                native_coroutine_with_adapter()
-            ),
+            self.asyncio_loop.run_until_complete(native_coroutine_with_adapter()),
             42,
         )
         self.assertEqual(
-            asyncio.get_event_loop().run_until_complete(
-                native_coroutine_with_adapter2()
-            ),
+            self.asyncio_loop.run_until_complete(native_coroutine_with_adapter2()),
             42,
         )
 
@@ -119,7 +116,7 @@ class LeakTest(unittest.TestCase):
         asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
 
     def tearDown(self):
-        asyncio.get_event_loop().close()
+        asyncio.get_event_loop_policy().get_event_loop().close()
         asyncio.set_event_loop_policy(self.orig_policy)
 
     def test_ioloop_close_leak(self):