diff --git a/slackbotExercise.py b/slackbotExercise.py index d66d712..8a40e5e 100644 --- a/slackbotExercise.py +++ b/slackbotExercise.py @@ -1,3 +1,5 @@ +import sys +import signal import random import time import requests @@ -17,7 +19,6 @@ HASH = "%23" - # Configuration values to be set in setConfiguration class Bot: def __init__(self): @@ -281,6 +282,11 @@ def isOfficeHours(bot): return False def main(): + + # Handle a SIGTERM so that killing the bot via other methods (like "docker stop") + # triggers the same functionality as Ctrl-C (KeyboardInterrupt) + signal.signal(signal.SIGTERM, lambda signum, frame: sys.exit(0)) + bot = Bot() try: @@ -303,7 +309,7 @@ def main(): # If debugging, check again in 5 seconds time.sleep(5) - except KeyboardInterrupt: + except (KeyboardInterrupt, SystemExit): saveUsers(bot)