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

Gunicorn logs `[CRITICAL] WORKER TIMEOUT (pid:42)` and requests fail with 502 from the load balancer.

AdvancedTroubleshootingConcurrency, async, tests, services & containers
Answer

Likely causes → A request took longer than gunicorn's --timeout (30s default) on a sync worker, usually a slow downstream call without a timeout, or CPU-bound work.

Diagnose → Correlate timeouts with endpoints in access logs; py-spy dump on a worker during a slow request.

Fix → Add timeouts to outbound calls, move long jobs to a background queue, use gthread or async workers for I/O-bound handlers, and raise --timeout only if the work is legitimately long.

Prevent → Latency histograms per endpoint and timeouts on all external calls.

All Python for DevOps questions Roadmap: Python for automation

More on Concurrency, async, tests, services & containers