Skip to content

Commit 274b446

Browse files
graingertdiegorusso
authored andcommitted
pythongh-131645: fix ResourceWarnings in test_asyncio.test_events (python#131646)
1 parent 15a5ad3 commit 274b446

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
@@ -55,9 +56,9 @@ def _test_get_event_loop_new_process__sub_proc():
5556
async def doit():
5657
return 'hello'
5758

58-
loop = asyncio.new_event_loop()
59-
asyncio._set_event_loop(loop)
60-
return loop.run_until_complete(doit())
59+
with contextlib.closing(asyncio.new_event_loop()) as loop:
60+
asyncio._set_event_loop(loop)
61+
return loop.run_until_complete(doit())
6162

6263

6364
class CoroLike:
@@ -3005,13 +3006,13 @@ async def main():
30053006
def test_get_running_loop_already_running(self):
30063007
async def main():
30073008
running_loop = asyncio.get_running_loop()
3008-
loop = asyncio.new_event_loop()
3009-
try:
3010-
loop.run_forever()
3011-
except RuntimeError:
3012-
pass
3013-
else:
3014-
self.fail("RuntimeError not raised")
3009+
with contextlib.closing(asyncio.new_event_loop()) as loop:
3010+
try:
3011+
loop.run_forever()
3012+
except RuntimeError:
3013+
pass
3014+
else:
3015+
self.fail("RuntimeError not raised")
30153016

30163017
self.assertIs(asyncio.get_running_loop(), running_loop)
30173018

0 commit comments

Comments
 (0)