]> git.ipfire.org Git - collecty.git/blobdiff - src/collecty/daemon.py
daemon: Don't wait until the worker thread has finished after sending shutdown signal
[collecty.git] / src / collecty / daemon.py
index bb46971493368d3d18789d118555870ac14c6268..0891f8a9f30a8405b6fb353ef3207f7a1cffc963 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 ###############################################################################
 #                                                                             #
 # collecty - A system statistics collection daemon for IPFire                 #
 #                                                                             #
 ###############################################################################
 
-import Queue as queue
 import datetime
 import multiprocessing
+import queue
 import rrdtool
 import signal
 import threading
 import time
 
-import bus
-import plugins
+from . import bus
+from . import plugins
 
-from constants import *
-from i18n import _
+from .constants import *
+from .i18n import _
 
 import logging
 log = logging.getLogger("collecty")
@@ -96,6 +96,11 @@ class Collecty(object):
                # Register signal handlers.
                self.register_signal_handler()
 
+               # Cannot do anything if no plugins have been initialised
+               if not self.plugins:
+                       log.critical(_("No plugins have been initialised"))
+                       return
+
                # Start the bus
                self.bus.start()
 
@@ -188,9 +193,9 @@ class Collecty(object):
                        Creates a number of worker threads
                """
                # If no number of threads is given, we will create as many as we have
-               # active processor cores but never less than four.
+               # active processor cores but never less than two.
                if num is None:
-                       num = max(multiprocessing.cpu_count(), 4)
+                       num = max(multiprocessing.cpu_count(), 2)
 
                worker_threads = []
 
@@ -265,9 +270,6 @@ class WorkerThread(threading.Thread):
        def shutdown(self):
                self.running = False
 
-               # Wait until all data has been written.
-               self.join()
-
 
 class WriteQueue(threading.Thread):
        def __init__(self, collecty, submit_interval):
@@ -335,7 +337,7 @@ class WriteQueue(threading.Thread):
                                results[result.file] = [result]
 
                # Write the collected data to disk
-               for filename, results in results.items():
+               for filename, results in list(results.items()):
                        self._commit_file(filename, results)
 
                duration = time.time() - time_start
@@ -367,8 +369,8 @@ class QueueObject(object):
        def __str__(self):
                return "%s:%s" % (self.time.strftime("%s"), self.data)
 
-       def __cmp__(self, other):
-               return cmp(self.time, other.time)
+       def __lt__(self, other):
+               return self.time < other.time
 
 
 class PluginTimer(object):
@@ -380,8 +382,8 @@ class PluginTimer(object):
        def __repr__(self):
                return "<%s %s>" % (self.__class__.__name__, self.deadline)
 
-       def __cmp__(self, other):
-               return cmp(self.deadline, other.deadline)
+       def __lt__(self, other):
+               return self.deadline < other.deadline
 
        def reset_deadline(self):
                self.deadline = datetime.datetime.utcnow() \