From 5db92dbe5907e17b9b6817b68119882764b6d21f Mon Sep 17 00:00:00 2001 From: Carl George Date: Sat, 7 Dec 2024 01:52:41 -0600 Subject: [PATCH] Avoid manual async loop management Python 3.14 removes the implicit creation of an event loop when running asyncio.get_event_loop(). Rather than manually managing the loop creation, switch the async tests to use the higher level asyncio.run() interface, as recommended by the standard library docs. https://docs.python.org/dev/whatsnew/3.14.html#id4 Resolves #741 --- tests/sh_test.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/sh_test.py b/tests/sh_test.py index d12c3dcf..8ff61211 100644 --- a/tests/sh_test.py +++ b/tests/sh_test.py @@ -1722,9 +1722,10 @@ async def consumer(q): self.assertEqual(msg, "hello") alternating.append(2) - loop = asyncio.get_event_loop() - fut = asyncio.gather(producer(q), consumer(q)) - loop.run_until_complete(fut) + async def main(): + await asyncio.gather(producer(q), consumer(q)) + + asyncio.run(main()) self.assertListEqual(alternating, [1, 2, 1, 2]) def test_async_exc(self): @@ -1733,8 +1734,7 @@ def test_async_exc(self): async def producer(): await python(py.name, _async=True) - loop = asyncio.get_event_loop() - self.assertRaises(sh.ErrorReturnCode_34, loop.run_until_complete, producer()) + self.assertRaises(sh.ErrorReturnCode_34, asyncio.run, producer()) def test_async_iter(self): py = create_tmp_test( @@ -1763,9 +1763,10 @@ async def consumer(q): return alternating.append(2) - loop = asyncio.get_event_loop() - res = asyncio.gather(producer(q), consumer(q)) - loop.run_until_complete(res) + async def main(): + await asyncio.gather(producer(q), consumer(q)) + + asyncio.run(main()) self.assertListEqual(alternating, [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) def test_async_iter_exc(self): @@ -1783,8 +1784,7 @@ async def producer(): async for line in python(py.name, _async=True): lines.append(int(line.strip())) - loop = asyncio.get_event_loop() - self.assertRaises(sh.ErrorReturnCode_34, loop.run_until_complete, producer()) + self.assertRaises(sh.ErrorReturnCode_34, asyncio.run, producer()) def test_handle_both_out_and_err(self): py = create_tmp_test(