From: Thorsten S Date: Wed, 1 May 2019 09:25:25 +0000 (+0200) Subject: fix plugin shutdown X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=86d92fc4c420ca7cc8f464c3bf7abc93d7db4e78;p=urlbot-v3.git fix plugin shutdown --- 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__':