]> git.aero2k.de Git - urlbot-v3.git/commitdiff
fix plugin shutdown
authorThorsten S <mail@aero2k.de>
Wed, 1 May 2019 09:25:25 +0000 (11:25 +0200)
committerThorsten S <mail@aero2k.de>
Wed, 1 May 2019 09:25:25 +0000 (11:25 +0200)
distbot/minijobber/run.py

index 219ca8efffc17018bf16aeaab51c2d44fdedf445..50309ab1bc88dd83aaf681a2137da81b90640fe7 100644 (file)
@@ -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__':