langchain_core.runnables.config
.ContextThreadPoolExecutorΒΆ
- class langchain_core.runnables.config.ContextThreadPoolExecutor(max_workers=None, thread_name_prefix='', initializer=None, initargs=())[source]ΒΆ
ThreadPoolExecutor that copies the context to the child thread.
Initializes a new ThreadPoolExecutor instance.
- Parameters
max_workers β The maximum number of threads that can be used to execute the given calls.
thread_name_prefix β An optional name prefix to give our threads.
initializer β A callable used to initialize worker threads.
initargs β A tuple of arguments to pass to the initializer.
Methods
__init__
([max_workers, thread_name_prefix, ...])Initializes a new ThreadPoolExecutor instance.
map
(fn, *iterables[, timeout, chunksize])Returns an iterator equivalent to map(fn, iter).
shutdown
([wait, cancel_futures])Clean-up the resources associated with the Executor.
submit
(func, *args, **kwargs)Submit a function to the executor.
- __init__(max_workers=None, thread_name_prefix='', initializer=None, initargs=())ΒΆ
Initializes a new ThreadPoolExecutor instance.
- Parameters
max_workers β The maximum number of threads that can be used to execute the given calls.
thread_name_prefix β An optional name prefix to give our threads.
initializer β A callable used to initialize worker threads.
initargs β A tuple of arguments to pass to the initializer.
- map(fn: Callable[[...], T], *iterables: Iterable[Any], timeout: float | None = None, chunksize: int = 1) Iterator[T] [source]ΒΆ
Returns an iterator equivalent to map(fn, iter).
- Parameters
fn β A callable that will take as many arguments as there are passed iterables.
timeout β The maximum number of seconds to wait. If None, then there is no limit on the wait time.
chunksize β The size of the chunks the iterable will be broken into before being passed to a child process. This argument is only used by ProcessPoolExecutor; it is ignored by ThreadPoolExecutor.
- Returns
map(func, *iterables) but the calls may be evaluated out-of-order.
- Return type
An iterator equivalent to
- Raises
TimeoutError β If the entire result iterator could not be generated before the given timeout.
Exception β If fn(*args) raises for any values.
- shutdown(wait=True, *, cancel_futures=False)ΒΆ
Clean-up the resources associated with the Executor.
It is safe to call this method several times. Otherwise, no other methods can be called after this one.
- Parameters
wait β If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed.
cancel_futures β If True then shutdown will cancel all pending futures. Futures that are completed or running will not be cancelled.
- submit(func: ~typing.Callable[[~P], ~langchain_core.runnables.config.T], *args: ~typing.~P, **kwargs: ~typing.~P) Future[T] [source]ΒΆ
Submit a function to the executor.
- Parameters
func (Callable[..., T]) β The function to submit.
*args (Any) β The positional arguments to the function.
**kwargs (Any) β The keyword arguments to the function.
- Returns
The future for the function.
- Return type
Future[T]