summaryrefslogtreecommitdiff
path: root/cherrypy/process/plugins.py
diff options
context:
space:
mode:
authorRobert Brewer <fumanchu@aminus.org>2011-07-04 06:27:38 +0000
committerRobert Brewer <fumanchu@aminus.org>2011-07-04 06:27:38 +0000
commit37b06b7322324c80f30ad3a23eb06d376f94f39a (patch)
tree1ad554dbac33b72ff0e29d75e4413ad2898a3544 /cherrypy/process/plugins.py
parentad80f344af03576a85709b6ccd540e52f766ebfe (diff)
downloadcherrypy-git-37b06b7322324c80f30ad3a23eb06d376f94f39a.tar.gz
Fix for #1070 (BackgroundTask refers to un-set "bus" member)
Diffstat (limited to 'cherrypy/process/plugins.py')
-rw-r--r--cherrypy/process/plugins.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/cherrypy/process/plugins.py b/cherrypy/process/plugins.py
index 488958eb..ba618a0b 100644
--- a/cherrypy/process/plugins.py
+++ b/cherrypy/process/plugins.py
@@ -453,13 +453,14 @@ class BackgroundTask(threading.Thread):
it won't delay stopping the whole process.
"""
- def __init__(self, interval, function, args=[], kwargs={}):
+ def __init__(self, interval, function, args=[], kwargs={}, bus=None):
threading.Thread.__init__(self)
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.running = False
+ self.bus = bus
def cancel(self):
self.running = False
@@ -473,8 +474,9 @@ class BackgroundTask(threading.Thread):
try:
self.function(*self.args, **self.kwargs)
except Exception:
- self.bus.log("Error in background task thread function %r." %
- self.function, level=40, traceback=True)
+ if self.bus:
+ self.bus.log("Error in background task thread function %r."
+ % self.function, level=40, traceback=True)
# Quit on first error to avoid massive logs.
raise
@@ -506,8 +508,8 @@ class Monitor(SimplePlugin):
if self.frequency > 0:
threadname = self.name or self.__class__.__name__
if self.thread is None:
- self.thread = BackgroundTask(self.frequency, self.callback)
- self.thread.bus = self.bus
+ self.thread = BackgroundTask(self.frequency, self.callback,
+ bus = self.bus)
self.thread.setName(threadname)
self.thread.start()
self.bus.log("Started monitor thread %r." % threadname)