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])

Map a function to multiple iterables.

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]#

Map a function to multiple iterables.

Parameters:
  • fn (Callable[..., T]) – The function to map.

  • *iterables (Iterable[Any]) – The iterables to map over.

  • timeout (float | None, optional) – The timeout for the map. Defaults to None.

  • chunksize (int, optional) – The chunksize for the map. Defaults to 1.

Returns:

The iterator for the mapped function.

Return type:

Iterator[T]

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]