SIGTERM in Python

As an example, if you want to handle SIGTERM in Python, then you can import the signal module and reference a handler to do whatever you want. For example, a simple shut down immediately and exit bit of code might be:

import signalimport sysdef sigterm_handler(_signo, _stack_frame):    sys.exit(0)signal.signal(signal.SIGTERM, sigterm_handler)

The signal handler logic can be as complex, or as simple, as your code requires.

Get Kubernetes for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.