Use threading.Event() for thread-safe shutdown signal. Main thread catches SIGTERM, sets event. Workers poll event in loops. Daemon threads auto-terminate. 5s join timeout prevents Kubernetes kills.
Test: python app.py & kill %1 → Clean exit <5s
How do you safely handle SIGTERM in multi-threaded Python services?
Use threading.Event() for thread-safe shutdown signal. Main thread catches SIGTERM, sets event. Workers poll event in loops. Daemon threads auto-terminate. 5s join timeout prevents Kubernetes kills.
Test: python app.py & kill %1 → Clean exit <5s