Created
April 16, 2018 05:56
-
-
Save funsim/56b362bad29cfbcc3879717883d3b191 to your computer and use it in GitHub Desktop.
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 threading | |
import signal | |
import sys | |
from time import sleep | |
class MyThread(threading.Thread): | |
def __init__(self): | |
threading.Thread.__init__(self) | |
self.is_running = False | |
def run(self): | |
self.is_running = True | |
while self.is_running: | |
print("Thread is running") | |
sleep(0.1) | |
print("Thread exiting") | |
def stop(self): | |
self.is_running = False | |
thread = MyThread() | |
thread.start() | |
def sigterm_handler(_signo, _stack_frame): | |
thread.stop() | |
sys.exit(0) | |
signal.signal(signal.SIGTERM, sigterm_handler) | |
signal.signal(signal.SIGINT, sigterm_handler) | |
signal.signal(signal.SIGHUP, sigterm_handler) | |
while True: | |
sleep(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment