Created
September 11, 2018 11:21
-
-
Save mrizvic/7dc7c345f02fabc1ba4cb9fe4422ef1e to your computer and use it in GitHub Desktop.
python signal handler template
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 | |
import time | |
import signal | |
import sys | |
import datetime | |
import inspect | |
def signalhandler (signum, frame): | |
print inspect.getframeinfo(frame) | |
print 'SIGNAL {0} caught.. byebye'.format(signum) | |
raise SystemExit | |
sys.exit(0) | |
def measure(signum, frame): | |
print inspect.getframeinfo(frame) | |
print '{} neki nardis zdej'.format(datetime.datetime.utcnow()) | |
signal.alarm(5) | |
return True | |
if __name__ == '__main__': | |
signal.signal(signal.SIGALRM, measure) | |
signal.signal(signal.SIGINT, signalhandler) | |
signal.signal(signal.SIGHUP, signalhandler) | |
signal.signal(signal.SIGABRT, signalhandler) | |
signal.signal(signal.SIGQUIT, signalhandler) | |
signal.signal(signal.SIGPIPE, signalhandler) | |
signal.signal(signal.SIGTERM, signalhandler) | |
signal.alarm(1) | |
while(True): | |
print '{} signal.pause'.format(datetime.datetime.utcnow()) | |
signal.pause() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment