I know that processes are periodically terminated due to runtime limitations or server reboots. How are the processes terminated? The following code should print a message to stdout upon exiting. This works when ^C-ing in a Console, but fails when consoles and tasks are killed (by the user or automatically).
A SIGTERM + grace period + SIGKILL approach would give long running processes a chance to save state gracefully in most cases. I believe that this is what systemd and docker do.
import atexit
import sleep
def complain_about_termination():
print('please, not the circle of life *#$! again... :-(')
atexit.register(complain_about_termination)
while True:
time.sleep(5)