mirror of
https://github.com/hwchase17/langchain.git
synced 2026-07-01 14:47:02 +00:00
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:
@@ -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),
|
||||
)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user