Interview Prep/Python for DevOps/Concurrency, async, tests, services & containers

A `ThreadPoolExecutor` job finishes "successfully" but half the work is missing, with no errors logged.

IntermediateTroubleshootingConcurrency, async, tests, services & containers
Answer

Likely causes → Exceptions inside worker functions are stored in the futures and only raised when .result() is called; the code submitted tasks and never checked results.

Diagnose → Iterate futures and call f.exception().

Fix →

for f in as_completed(futures):
    try:
        f.result()
    except Exception:
        log.exception("task %s failed", futures[f])
        failures += 1
sys.exit(1 if failures else 0)

Prevent → Always consume results; fail the run when any task fails.

All Python for DevOps questions Roadmap: Python for automation

More on Concurrency, async, tests, services & containers