Robert Brewer avatar 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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.