Is there any way to run one last command before a running Python script is stopped by being killed by some other script, keyboard interrupt etc.
import signal import sys import time def cleanup(*args): print 'Exiting' sys.exit(0) signal.signal(signal.SIGINT, cleanup) signal.signal(signal.SIGTERM, cleanup) while True: time.sleep(60) # less busy loop