mirror of
https://github.com/python/cpython.git
synced 2025-09-11 19:27:07 +00:00
gh-131645: fix ResourceWarnings in test_asyncio.test_events
(#131646)
This commit is contained in:
parent
01ea4c77e5
commit
71ce4acb25
1 changed files with 11 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
"""Tests for events.py."""
|
"""Tests for events.py."""
|
||||||
|
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
|
import contextlib
|
||||||
import functools
|
import functools
|
||||||
import io
|
import io
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
@ -55,9 +56,9 @@ def _test_get_event_loop_new_process__sub_proc():
|
||||||
async def doit():
|
async def doit():
|
||||||
return 'hello'
|
return 'hello'
|
||||||
|
|
||||||
loop = asyncio.new_event_loop()
|
with contextlib.closing(asyncio.new_event_loop()) as loop:
|
||||||
asyncio._set_event_loop(loop)
|
asyncio._set_event_loop(loop)
|
||||||
return loop.run_until_complete(doit())
|
return loop.run_until_complete(doit())
|
||||||
|
|
||||||
|
|
||||||
class CoroLike:
|
class CoroLike:
|
||||||
|
@ -3005,13 +3006,13 @@ class GetEventLoopTestsMixin:
|
||||||
def test_get_running_loop_already_running(self):
|
def test_get_running_loop_already_running(self):
|
||||||
async def main():
|
async def main():
|
||||||
running_loop = asyncio.get_running_loop()
|
running_loop = asyncio.get_running_loop()
|
||||||
loop = asyncio.new_event_loop()
|
with contextlib.closing(asyncio.new_event_loop()) as loop:
|
||||||
try:
|
try:
|
||||||
loop.run_forever()
|
loop.run_forever()
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.fail("RuntimeError not raised")
|
self.fail("RuntimeError not raised")
|
||||||
|
|
||||||
self.assertIs(asyncio.get_running_loop(), running_loop)
|
self.assertIs(asyncio.get_running_loop(), running_loop)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue