run_in_executor() — langchain Function Reference
Architecture documentation for the run_in_executor() function in config.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 6476e334_3d94_a55a_3c07_669af2558871["run_in_executor()"] 4d16987d_fe07_22bb_f46d_7daeb24e0367["config.py"] 6476e334_3d94_a55a_3c07_669af2558871 -->|defined in| 4d16987d_fe07_22bb_f46d_7daeb24e0367 style 6476e334_3d94_a55a_3c07_669af2558871 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/runnables/config.py lines 598–632
async def run_in_executor(
executor_or_config: Executor | RunnableConfig | None,
func: Callable[P, T],
*args: P.args,
**kwargs: P.kwargs,
) -> T:
"""Run a function in an executor.
Args:
executor_or_config: The executor or config to run in.
func: The function.
*args: The positional arguments to the function.
**kwargs: The keyword arguments to the function.
Returns:
The output of the function.
"""
def wrapper() -> T:
try:
return func(*args, **kwargs)
except StopIteration as exc:
# StopIteration can't be set on an asyncio.Future
# it raises a TypeError and leaves the Future pending forever
# so we need to convert it to a RuntimeError
raise RuntimeError from exc
if executor_or_config is None or isinstance(executor_or_config, dict):
# Use default executor with context copied from current context
return await asyncio.get_running_loop().run_in_executor(
None,
cast("Callable[..., T]", partial(copy_context().run, wrapper)),
)
return await asyncio.get_running_loop().run_in_executor(executor_or_config, wrapper)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does run_in_executor() do?
run_in_executor() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/config.py.
Where is run_in_executor() defined?
run_in_executor() is defined in libs/core/langchain_core/runnables/config.py at line 598.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free