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
- Logs — which endpoint was running when it timed out? Enable access logs (
--access-logfile -). - 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 - CPU throttling — check
kubectl top podand throttling metrics; a tiny CPU limit with several workers makes everything slow. - Memory — workers swapping or close to the limit get slow, then OOMKilled.
- Long-running work — move reports/exports to a background queue (Celery, RQ) instead of doing them in the request.
- 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)
How do you install dependencies and run a Python application?BeginnerWhat is a Python virtual environment and why do we need it?BeginnerWhat is requirements.txt and how do you pin versions?BeginnerHow do you run a Flask application in development and in production?BeginnerWhat is gunicorn and how many workers should you run?BeginnerWhat is the difference between WSGI and ASGI?Intermediate