Created
May 23, 2018 11:55
-
-
Save MrKich/6b1c2f609c4a986bddc9fa291a60c1a9 to your computer and use it in GitHub Desktop.
Simple class for catching exit signals
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
import threading | |
import signal | |
class SignalExitter: | |
def __init__(self): | |
self.event = threading.Event() | |
signal.signal(signal.SIGINT, self._exit_by_signal) | |
signal.signal(signal.SIGTERM, self._exit_by_signal) | |
def _exit_by_signal(self, signum, frame): | |
self.event.set() | |
def wait(self, timeout=None): | |
return self.event.wait(timeout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment