Python Glossary Русский

Python 3.2+concurrent.futuresterm

concurrent.futures.Future

asynchronous result

An object representing the result of an operation carried out asynchronously. Returned by submit(). It lets you check the status and collect the result.

Syntax

f = executor.submit(fn, *args)
f.result()   # блокирует до готовности
f.done()     # True если завершён
f.cancel()   # отменить, если ещё не запущен

An exception inside the task does not surface on its own: it is stored in the Future and only re-raised when you call result() (or exception()). If nobody asks for the result, the error vanishes without a trace — the classic reason a worker "did nothing and said nothing". Also avoid calling result() inside the submit loop: it blocks and turns the pool back into sequential execution — collect the futures first, then walk them with as_completed().

Examples

from concurrent.futures import ThreadPoolExecutor
with ThreadPoolExecutor() as ex:
    f = ex.submit(sum, range(1000))
    print(f.done())     # False или True
    print(f.result())   # 499500 — блокирует

See also

Open in the full glossarydocs.python.orgReport an inaccuracy