Skip to content

Commit 9f36dff

Browse files
authored
[3.13] pythongh-131645: fix ResourceWarnings in test_asyncio.test_events (python#131646) (python#131661)
pythongh-131645: fix ResourceWarnings in `test_asyncio.test_events` (python#131646) (cherry picked from commit 71ce4ac)
1 parent 478eb73 commit 9f36dff

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Lib/test/test_asyncio/test_events.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for events.py."""
22

33
import concurrent.futures
4+
import contextlib
45
import functools
56
import io
67
import multiprocessing
@@ -57,9 +58,9 @@ def _test_get_event_loop_new_process__sub_proc():
5758
async def doit():
5859
return 'hello'
5960

60-
loop = asyncio.new_event_loop()
61-
asyncio.set_event_loop(loop)
62-
return loop.run_until_complete(doit())
61+
with contextlib.closing(asyncio.new_event_loop()) as loop:
62+
asyncio.set_event_loop(loop)
63+
return loop.run_until_complete(doit())
6364

6465

6566
class CoroLike:
@@ -2892,13 +2893,13 @@ async def main():
28922893
def test_get_running_loop_already_running(self):
28932894
async def main():
28942895
running_loop = asyncio.get_running_loop()
2895-
loop = asyncio.new_event_loop()
2896-
try:
2897-
loop.run_forever()
2898-
except RuntimeError:
2899-
pass
2900-
else:
2901-
self.fail("RuntimeError not raised")
2896+
with contextlib.closing(asyncio.new_event_loop()) as loop:
2897+
try:
2898+
loop.run_forever()
2899+
except RuntimeError:
2900+
pass
2901+
else:
2902+
self.fail("RuntimeError not raised")
29022903

29032904
self.assertIs(asyncio.get_running_loop(), running_loop)
29042905

0 commit comments

Comments
 (0)