Interview Prep/Build Tools (Java, Node.js, Python, .NET)/Python builds (pip, venv, requirements.txt)

A Python app in Kubernetes logs "WORKER TIMEOUT" and restarts workers. How do you troubleshoot?

IntermediateTroubleshootingPython builds (pip, venv, requirements.txt)
Answer

Short answer

Gunicorn killed a worker because one request took longer than --timeout (default 30 seconds). Find out what's slow — a database query, an external API call, CPU-heavy work, or a CPU limit throttling the pod — and fix that; only raise the timeout if long requests are expected.

Steps

  1. Logs — which endpoint was running when it timed out? Enable access logs (--access-logfile -).
  2. Dependencies — is the DB or a third-party API slow? Add client timeouts so calls fail fast instead of hanging forever:
    requests.get(url, timeout=(3, 10))     # 3s connect, 10s read
    
  3. CPU throttling — check kubectl top pod and throttling metrics; a tiny CPU limit with several workers makes everything slow.
  4. Memory — workers swapping or close to the limit get slow, then OOMKilled.
  5. Long-running work — move reports/exports to a background queue (Celery, RQ) instead of doing them in the request.
  6. Tune if justified — --timeout 120, or -k gthread/async workers for I/O-heavy apps.

What to say in the interview

"WORKER TIMEOUT means a request exceeded gunicorn's timeout. I identify the slow endpoint from access logs, check downstream latency and CPU throttling, add client-side timeouts, and move long tasks to a background queue before considering a longer timeout."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Python apps: pip, venv & requirements.txt

More on Python builds (pip, venv, requirements.txt)