langchain_core.runnables.config
.ContextThreadPoolExecutor¶
- class langchain_core.runnables.config.ContextThreadPoolExecutor(max_workers=None, thread_name_prefix='', initializer=None, initargs=())[source]¶
将上下文复制到子线程的ThreadPoolExecutor。
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)提交一个函数给执行器。
- __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 (Callable[[...], T]) – A callable that will take as many arguments as there are passed iterables.
timeout (float | None) – The maximum number of seconds to wait. If None, then there is no limit on the wait time.
chunksize (int) – 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.
iterables (Iterable[Any]) –
- 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]¶
提交一个函数给执行器。
- 参数:
func (Callable[…, T]): 要提交的函数。 *args (Any): 函数的位置参数。 **kwargs (Any): 函数的关键字参数。
- 返回:
Future[T]: 函数的future。
- Parameters
func (Callable[[~P], T]) –
args (~P) –
kwargs (~P) –
- Return type
Future[T]