concurrent.futures.ThreadPoolExecutor()
concurrent.futures.ThreadPoolExecutor() is a Python function in the Concurrent Module category. Creates a thread pool for executing callables asynchronously. The syntax is concurrent.futures.ThreadPoolExecutor(max_workers=None, thread_name_prefix="", initializer=None, initargs=()). Returns: ThreadPoolExecutor object. A typical example: from concurrent.futures import ThreadPoolExecutor
with ThreadPoolExecutor(max_workers=4) as ex:
futures = [ex.submit(fetch_url, url) for url in urls]
for f in futures:
print(f.result()). A close sibling is concurrent.futures.ProcessPoolExecutor(), which creates a process pool for CPU-bound parallel execution. A close sibling is Executor.submit(), which schedules a callable to be executed and returns a Future. A close sibling is Executor.map(), which maps a function across iterables in parallel (like built-in map). A close sibling is Future.result(), which returns the result of the callable when complete. Blocks if not yet done. More about this category: Thread/process pools — ThreadPoolExecutor, ProcessPoolExecutor, Future. Related Concurrent Module entries: concurrent.futures.ProcessPoolExecutor(), Executor.submit(), Executor.map(), Future.result(), Future.done(), Future.cancel(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.