Created
January 29, 2015 16:20
-
-
Save zertrin/62452aefe2fdf78cae26 to your computer and use it in GitHub Desktop.
Cleaning up when killed (Python recipe)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# From http://code.activestate.com/recipes/533117-cleaning-up-when-killed/ | |
from signal import signal, SIGTERM | |
from sys import exit | |
import atexit | |
def cleanup(): | |
print "Cleanup" | |
if __name__ == "__main__": | |
from time import sleep | |
atexit.register(cleanup) | |
# Normal exit when killed | |
signal(SIGTERM, lambda signum, stack_frame: exit(1)) | |
sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment