Interview Prep/Python for DevOps/Kubernetes, Docker, SSH & fleet automation

A Python service in a container takes 30 seconds to stop during deploys. What do you look at?

IntermediateScenarioKubernetes, Docker, SSH & fleet automation
Answer

Situation read → The process is not handling SIGTERM, so it waits for SIGKILL after the grace period.

What I'd do →

  1. Check the Dockerfile uses exec-form ENTRYPOINT ["gunicorn", ...], not a shell form where /bin/sh is PID 1 and swallows signals.
  2. Confirm the app or server handles SIGTERM (gunicorn and uvicorn do; custom loops need a handler).
  3. For custom workers, install a signal.signal(signal.SIGTERM, ...) handler that stops accepting work and exits.
  4. Use tini (docker run --init) if the app spawns children.

Why → Proper signal handling means fast, graceful shutdowns and no dropped requests.

Interview tip → "Shell-form CMD makes sh PID 1" is the usual root cause.

All Python for DevOps questions Roadmap: Python for automation

More on Kubernetes, Docker, SSH & fleet automation