How to handle an ACPI G2 Soft Off signal in Python

10/23/2019

I am running a Python program on a Preemtible machine on Kubernetes. This type of instance stops randomly, and when it does, it sends a ACPI G2 Soft Off signal before the stop. I want to be able to handler it on Python. I have the following code to handler other signals too:

def signal_handler(signal, frame):
    _logger.info("Exit the program due to signal {}".format(signal))
    sys.exit(0)

if __name__ == '__main__':
    signal.signal(signal.SIGTERM, signal_handler)
    main()
-- Dani Gonzalez
kubernetes
python
signals

0 Answers