CertGrid CertGrid
Troubleshooting·Python Automation for IT

Python Signals, Timeouts and Process Termination

An automation script that can hang for ever is worse than one that fails, because nobody finds out. This guide covers the timeout that stops a child, the timeout that leaves it running, escalating from `terminate` to `kill`, what a negative return code means, and how to catch SIGTERM so your own script finishes the item it is on rather than dying in the middle of it.

OS and Process Automation Guide 21 of 39 Intermediate

Written against the versions above. `signal.Signals` as an enum needs Python 3.5, and `signal.raise_signal` 3.8. Signal handlers only run in the main thread of the main interpreter, which has always been true.

Everything on this page runs on the control node. Any machine with Python 3 will do.
Server NameIP AddressOSRolesCPURAMHDD
RUNNER01192.168.0.27Ubuntu 26.04 LTSControl node - every script in this path runs here2 Core4 GB50 GB

Before you start

  1. A child that takes too long

  2. The timeout that does not stop the child

  3. terminate, then kill

  4. What a return code says about a signal

  5. Handling a signal in your own script

  6. And what a bare kill -9 costs you

  7. The one signal you cannot catch

  8. A timeout you enforce on yourself

Official sources