Skip to content

Instantly share code, notes, and snippets.

@Kenji-H
Last active October 21, 2017 09:14
Show Gist options
  • Save Kenji-H/e75c1ca44497c3db964080dcebe9cf3f to your computer and use it in GitHub Desktop.
Save Kenji-H/e75c1ca44497c3db964080dcebe9cf3f to your computer and use it in GitHub Desktop.
Signal Handler in Python
import signal
import time
def sigint_handler(num, frame):
print("received SIGINT!")
def sigtstp_handler(num, frame):
print("received SIGTSTP!")
def sigterm_handler(num, frame):
print("received SIGTERM!")
def work():
while True:
time.sleep(1)
print("this is a signal handler sample!")
def main():
signal.signal(signal.SIGINT, sigint_handler)
signal.signal(signal.SIGTSTP, sigtstp_handler)
signal.signal(signal.SIGTERM, sigterm_handler)
work()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment