Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle sigterm just like a ctrl-c (keyboard interrupt) #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions slackbotExercise.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys
import signal
import random
import time
import requests
Expand All @@ -17,7 +19,6 @@

HASH = "%23"


# Configuration values to be set in setConfiguration
class Bot:
def __init__(self):
Expand Down Expand Up @@ -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:
Expand All @@ -303,7 +309,7 @@ def main():
# If debugging, check again in 5 seconds
time.sleep(5)

except KeyboardInterrupt:
except (KeyboardInterrupt, SystemExit):
saveUsers(bot)


Expand Down