14 lines
375 B
Python
14 lines
375 B
Python
# Based on https://stackoverflow.com/questions/18499497/how-to-process-sigterm-signal-gracefully
|
|
|
|
import signal
|
|
|
|
|
|
class Terminator:
|
|
terminate = False
|
|
|
|
def __init__(self):
|
|
signal.signal(signal.SIGINT, self.exit_gracefully)
|
|
signal.signal(signal.SIGTERM, self.exit_gracefully)
|
|
|
|
def exit_gracefully(self, signum, frame):
|
|
self.terminate = True
|