https://github.com/python/cpython/commit/9f36dff788c10123a7e886135814da8acb58eeea
commit: 9f36dff788c10123a7e886135814da8acb58eeea
branch: 3.13
author: Thomas Grainger <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2025-03-24T13:18:57Z
summary:
[3.13] gh-131645: fix ResourceWarnings in `test_asyncio.test_events` (#131646)
(#131661)
gh-131645: fix ResourceWarnings in `test_asyncio.test_events` (#131646)
(cherry picked from commit 71ce4acb25eb640a4582904172d2bb9600983f4c)
files:
M Lib/test/test_asyncio/test_events.py
diff --git a/Lib/test/test_asyncio/test_events.py
b/Lib/test/test_asyncio/test_events.py
index 06a72aa798092b..9c068522da1c11 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -1,6 +1,7 @@
"""Tests for events.py."""
import concurrent.futures
+import contextlib
import functools
import io
import multiprocessing
@@ -57,9 +58,9 @@ def _test_get_event_loop_new_process__sub_proc():
async def doit():
return 'hello'
- loop = asyncio.new_event_loop()
- asyncio.set_event_loop(loop)
- return loop.run_until_complete(doit())
+ with contextlib.closing(asyncio.new_event_loop()) as loop:
+ asyncio.set_event_loop(loop)
+ return loop.run_until_complete(doit())
class CoroLike:
@@ -2892,13 +2893,13 @@ async def main():
def test_get_running_loop_already_running(self):
async def main():
running_loop = asyncio.get_running_loop()
- loop = asyncio.new_event_loop()
- try:
- loop.run_forever()
- except RuntimeError:
- pass
- else:
- self.fail("RuntimeError not raised")
+ with contextlib.closing(asyncio.new_event_loop()) as loop:
+ try:
+ loop.run_forever()
+ except RuntimeError:
+ pass
+ else:
+ self.fail("RuntimeError not raised")
self.assertIs(asyncio.get_running_loop(), running_loop)
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]