diff options
author | Robert Brewer <fumanchu@aminus.org> | 2011-07-04 06:27:38 +0000 |
---|---|---|
committer | Robert Brewer <fumanchu@aminus.org> | 2011-07-04 06:27:38 +0000 |
commit | 37b06b7322324c80f30ad3a23eb06d376f94f39a (patch) | |
tree | 1ad554dbac33b72ff0e29d75e4413ad2898a3544 /cherrypy/process/plugins.py | |
parent | ad80f344af03576a85709b6ccd540e52f766ebfe (diff) | |
download | cherrypy-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.py | 12 |
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) |