From 86d92fc4c420ca7cc8f464c3bf7abc93d7db4e78 Mon Sep 17 00:00:00 2001 From: Thorsten S Date: Wed, 1 May 2019 11:25:25 +0200 Subject: [PATCH] fix plugin shutdown --- distbot/minijobber/run.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/distbot/minijobber/run.py b/distbot/minijobber/run.py index 219ca8e..50309ab 100644 --- a/distbot/minijobber/run.py +++ b/distbot/minijobber/run.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import logging import signal from time import sleep @@ -7,9 +8,13 @@ from distbot.common.config import conf_get from distbot.bot import worker as worker_mod -from distbot.plugins import basic, fun, lookup, url, feeds, muc, translation, searx, queue_management, plugin_help, \ - morse, meta, \ - extended, bugtracker, bots, bofh +from distbot.plugins import ( + basic, fun, lookup, url, feeds, muc, translation, searx, queue_management, plugin_help, + morse, meta, + extended, bugtracker, bots, bofh, + debug +) +logger = logging.getLogger(__name__) WORKER_QUEUE = "work" # TODO read from config @@ -31,6 +36,7 @@ PLUGIN_MODULES = { searx: searx.ALL, translation: translation.ALL, url: url.ALL, + # debug: debug.ALL } job_workers = [] @@ -72,11 +78,11 @@ def reset_workers(signum, frame): def stop_workers(signum, frame): - print("stopping workers") + logger.info("stopping workers") [t.die() for t in job_workers] - print("joining workers") + logger.info("joining workers") [t.join() for t in job_workers] - print("stopped workers.") + logger.info("stopped workers.") job_workers.clear() @@ -91,8 +97,14 @@ def run(): # signal.signal(signal.SIGHUP, reset_workers) signal.signal(signal.SIGALRM, dump_status) initialize_workers() - while True: - sleep(100) + try: + while True: + sleep(100) + except KeyboardInterrupt: + import os + os.kill(os.getpid(), signal.SIGTERM) + logger.info("Exiting...") + exit(0) if __name__ == '__main__': -- 2.39.2