From a93c0b8f1580122b72e83f80182452c594684988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20H=C3=B6nig?= Date: Wed, 11 Jan 2017 17:57:59 +0000 Subject: [PATCH] Terminate run.py without throwing tracebacks. Pressing control-c while run.py is being executed has terminated the script, but threw an ugly traceback. To signal the user that his method of exit was appropriate, we handle control-c calling exit(0). --- contrib_bots/run.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contrib_bots/run.py b/contrib_bots/run.py index 06a3ad5..89a20c1 100755 --- a/contrib_bots/run.py +++ b/contrib_bots/run.py @@ -5,6 +5,7 @@ import importlib import logging import optparse import os +import signal import sys import time @@ -16,6 +17,9 @@ if os.path.exists(os.path.join(our_dir, '../api/zulip')): from zulip import Client +def exit_gracefully(signum, frame): + sys.exit(0) + class RateLimit(object): def __init__(self, message_limit, interval_limit): self.message_limit = message_limit @@ -147,4 +151,6 @@ def run(): ) if __name__ == '__main__': + original_sigint = signal.getsignal(signal.SIGINT) + signal.signal(signal.SIGINT, exit_gracefully) run()