fix(core): use asyncio.get_running_loop() in async contexts (#38157)

Closes #35726

---

Several async functions called `asyncio.get_event_loop()`, which has
been deprecated since Python 3.10. Inside `async def` bodies the loop is
always running, so `asyncio.get_running_loop()` is the correct,
warning-free replacement with no behavior change.

This updates the call in `_ahandle_event_for_handler` (core callbacks),
`_render_mermaid_using_pyppeteer` (core runnables graph), and
`async_api_key_wrapper` (`langchain-openai` client utils). Users running
on modern Python no longer see `DeprecationWarning`s from these paths.

Made by [Open SWE](https://openswe.vercel.app)

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
This commit is contained in:
Mason Daugherty
2026-06-22 22:26:16 -04:00
committed by GitHub
parent f7e87f7ab8
commit 3b48f48458
3 changed files with 3 additions and 3 deletions

View File

@@ -416,7 +416,7 @@ async def _ahandle_event_for_handler(
elif handler.run_inline:
event(*args, **kwargs)
else:
await asyncio.get_event_loop().run_in_executor(
await asyncio.get_running_loop().run_in_executor(
None,
functools.partial(copy_context().run, event, *args, **kwargs),
)

View File

@@ -395,7 +395,7 @@ async def _render_mermaid_using_pyppeteer(
await browser.close()
if output_file_path is not None:
await asyncio.get_event_loop().run_in_executor(
await asyncio.get_running_loop().run_in_executor(
None, Path(output_file_path).write_bytes, img_bytes
)

View File

@@ -550,7 +550,7 @@ def _resolve_sync_and_async_api_keys(
sync_api_key_value = cast(Callable, api_key)
async def async_api_key_wrapper() -> str:
return await asyncio.get_event_loop().run_in_executor(
return await asyncio.get_running_loop().run_in_executor(
None, cast(Callable, api_key)
)