Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import signal
- import threading
- class Server(threading.Thread):
- def __init__(self, *args, **kwargs):
- self._active = False
- super().__init__(*args, **kwargs)
- def run(self):
- self._active = True
- while self._active:
- time.sleep(1)
- def stop(self):
- print('Stopping process...')
- self._active = False
- def stop_server(sig, frame):
- server.stop()
- if __name__ == '__main__':
- server = Server()
- server.start()
- signal.signal(signal.SIGINT, stop_server)
- print('Stop Thread with CTRL+C')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement