Created
March 22, 2018 10:53
-
-
Save klikstermkd/013c09bc3635ad03e52964b90135698b to your computer and use it in GitHub Desktop.
Gracefully kill Python process
This file contains hidden or 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
from time import sleep | |
import signal | |
import sys | |
def on_stop_handler(signum, frame): | |
print 'Exiting application...' | |
sys.exit(0) | |
def listen_stop_signal(): | |
signal.signal(signal.SIGINT, on_stop_handler) | |
signal.signal(signal.SIGTERM, on_stop_handler) | |
def main_loop(): | |
listen_stop_signal() | |
while True: | |
sleep(1) | |
print 'Working...' | |
main_loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment