diff --git a/vcr/stubs/httpx_stubs.py b/vcr/stubs/httpx_stubs.py index 508996b1..fed7ed5d 100644 --- a/vcr/stubs/httpx_stubs.py +++ b/vcr/stubs/httpx_stubs.py @@ -174,12 +174,12 @@ def _run_async_function(sync_func, *args, **kwargs): - No event loop exists yet. """ try: - asyncio.get_running_loop() + loop = asyncio.get_running_loop() except RuntimeError: return asyncio.run(sync_func(*args, **kwargs)) else: # If inside a running loop, create a task and wait for it - return asyncio.ensure_future(sync_func(*args, **kwargs)) + return asyncio.run_coroutine_threadsafe(sync_func(*args, **kwargs), loop) def _sync_vcr_send(cassette, real_send, *args, **kwargs):