Last active
October 21, 2017 09:14
-
-
Save Kenji-H/e75c1ca44497c3db964080dcebe9cf3f to your computer and use it in GitHub Desktop.
Signal Handler in Python
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
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