Python Future.result timeout
A pending future raises a timeout when its available wait is zero.
A simple example
Future.result timeout
- Start with An unfinished task
- Do this Wait only until a deadline
- Result Time limit reached
Syntax
quote.result(timeout=0)
Run these examples in Python
Save one example at a time as lesson.py. Use Python 3.9 or later.
python3 lesson.pyLimit the wait for a shipping quote
A checkout screen has used its entire waiting budget for a carrier quote. The quote is still pending, so the customer should see a pending message while the underlying work remains available.
from concurrent.futures import Future, TimeoutError
quote = Future()
try:
print(quote.result(timeout=0))
except TimeoutError:
print("Quote pending")
Quote pending
There is no result within the zero-length wait, so checkout reports a pending quote immediately.
Poll a finished download
A document download has already completed when the kiosk checks. Inspect the job using a zero-wait poll. A job that has yet to complete stays in the waiting queue.
Poll a pending proof
A designer checks a pending proof without blocking the screen. Inspect the job using a zero-wait poll. A job that has yet to complete stays in the waiting queue.
What to watch for
This timeout limits the caller's wait. The future can still finish later.