1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 01:03:24 +00:00

use asyncio.run to run coroutines

This commit is contained in:
Thomas Grainger
2023-12-15 11:39:51 +00:00
parent f075c8b0b4
commit 895ae205ca

View File

@@ -14,10 +14,10 @@ from .aiohttp_utils import aiohttp_app, aiohttp_request # noqa: E402
def run_in_loop(fn): def run_in_loop(fn):
with contextlib.closing(asyncio.new_event_loop()) as loop: async def wrapper():
asyncio.set_event_loop(loop) return await fn(asyncio.get_running_loop())
task = loop.create_task(fn(loop))
return loop.run_until_complete(task) return asyncio.run(wrapper())
def request(method, url, output="text", **kwargs): def request(method, url, output="text", **kwargs):