summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Plugin/interfaces.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-11-27 11:49:47 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-11-27 12:12:34 -0500
commitc19e7da20ca6b67956338f9808a80673e06b1e94 (patch)
tree5d62c7c7aaf71e062f8bf22cbce987b8555ad78b /src/lib/Bcfg2/Server/Plugin/interfaces.py
parentfbecb8553136649eaf563d4f7ec21553500e5f16 (diff)
downloadbcfg2-c19e7da20ca6b67956338f9808a80673e06b1e94.tar.gz
bcfg2-c19e7da20ca6b67956338f9808a80673e06b1e94.tar.bz2
bcfg2-c19e7da20ca6b67956338f9808a80673e06b1e94.zip
Threaded plugin fixes:
* Added "Threaded" plugin interface for any plugin that uses threads * Start plugin threads after daemonization * Update existing plugins that use threads (Reporting, Snapshots, ThreadedStatistics interface) * Update unit tests
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugin/interfaces.py')
-rw-r--r--src/lib/Bcfg2/Server/Plugin/interfaces.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/lib/Bcfg2/Server/Plugin/interfaces.py b/src/lib/Bcfg2/Server/Plugin/interfaces.py
index 202ec7533..f42ada773 100644
--- a/src/lib/Bcfg2/Server/Plugin/interfaces.py
+++ b/src/lib/Bcfg2/Server/Plugin/interfaces.py
@@ -299,12 +299,27 @@ class Statistics(Plugin):
raise NotImplementedError
-class ThreadedStatistics(Statistics, threading.Thread):
+class Threaded(object):
+ """ Threaded plugins use threads in any way. The thread must be
+ started after daemonization, so this class implements a single
+ method, :func:`start_threads`, that can be used to start threads
+ after daemonization of the server core. """
+
+ def start_threads(self):
+ """ Start this plugin's threads after daemonization.
+
+ :return: None
+ :raises: :class:`Bcfg2.Server.Plugin.exceptions.PluginInitError`
+ """
+ raise NotImplementedError
+
+class ThreadedStatistics(Statistics, Threaded, threading.Thread):
""" ThreadedStatistics plugins process client statistics in a
separate thread. """
def __init__(self, core, datastore):
Statistics.__init__(self, core, datastore)
+ Threaded.__init__(self)
threading.Thread.__init__(self)
# Event from the core signaling an exit
self.terminate = core.terminate
@@ -312,6 +327,8 @@ class ThreadedStatistics(Statistics, threading.Thread):
self.pending_file = os.path.join(datastore, "etc",
"%s.pending" % self.name)
self.daemon = False
+
+ def start_threads(self):
self.start()
def _save(self):