Commits

Robert Brewer committed 62cc6e9

Fix for #1070 (BackgroundTask refers to un-set "bus" member)

Comments (0)

Files changed (1)

cherrypy/process/plugins.py

     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
             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
     
         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)