29/34
Part 8 of 8 · Follow-upsLearn

A timeout on result() stops your waiting, not the call

A step that hangs needs a timeout. Know what the timeout actually stops.

with ThreadPoolExecutor(max_workers=1) as pool:
    future = pool.submit(time.sleep, 0.5)
    # raises TimeoutError
    future.result(timeout=0.1)
Predict

result(timeout=0.1) on a call that sleeps 0.5 s raises TimeoutError at 0.1 s. When does leaving the with block finish?

Pick an answer above to see the rest