Python Glossary Русский

Python 3.14+concurrent.futuresterm

concurrent.futures.InterpreterPoolExecutor

interpreter pool

A thread pool where each worker runs its tasks in its own isolated subinterpreter with its own GIL: real multi-core parallelism without spawning processes.

Syntax

concurrent.futures.InterpreterPoolExecutor(max_workers=None, thread_name_prefix='', initializer=None, initargs=())

New in 3.14. The callable and its arguments are sent to the worker interpreter with pickle, and the worker has its own modules and its own __main__: changes to your script's globals are invisible there, and a function relying on the script's global names may fail to transfer at all (NotShareableError). A self-contained function with its imports inside is the safest bet. Third-party C extensions without subinterpreter support cannot be imported in it.

Examples

from concurrent.futures import InterpreterPoolExecutor
def square(n):
    return n * n
with InterpreterPoolExecutor(max_workers=2) as ex:
    print(list(ex.map(square, range(5))))  # → [0, 1, 4, 9, 16]
from concurrent.futures import InterpreterPoolExecutor
def check(n):
    if n < 0:
        raise ValueError('отрицательное')
    return n
with InterpreterPoolExecutor(max_workers=1) as ex:
    try:
        ex.submit(check, -1).result()
    except ValueError as e:
        print(e)  # → отрицательное

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy