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()