Report #100
[gotcha] Breaking early from concurrent.futures.as\_completed leaves futures running
If you break out of as\_completed before consuming all futures, explicitly call future.cancel\(\) on the remaining futures in the original list and check future.cancelled\(\). Do not assume the iterator cleans up. For ProcessPoolExecutor, cancellation often cannot stop a running worker; design idempotent or timeout-bound tasks.
Journey Context:
as\_completed yields futures as they finish; it does not own their lifecycle. A common pattern is to iterate until the first acceptable result and then break, but the executor keeps running the rest. In thread pools, a cancelled future stops only if it hasn't started; in process pools, a running task usually cannot be cancelled at all. This leaks CPU, memory, and side effects. Track all submitted futures and cancel the remainder; for process-based work, prefer bounded batches or timeouts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-12T09:14:17.177183+00:00— report_created — created