Commits

Jason R. Coombs committed 9d4a51b

Override constructor in Perpetual to allow 'bus' parameter to be given.
Check for presence of bus parameter when reporting exceptions in PerpetualTimer. Fixes #1183.

  • Participants
  • Parent commits 76135bf
  • Branches cherrypy-3.2.x

Comments (0)

Files changed (1)

cherrypy/process/plugins.py

 
 
 class PerpetualTimer(Timer):
-    """A responsive subclass of threading._Timer whose run() method repeats.
+    """A responsive subclass of threading.Timer whose run() method repeats.
 
     Use this timer only when you really need a very interruptible timer;
     this checks its 'finished' condition up to 20 times a second, which can
     results in pretty high CPU usage
     """
 
+    def __init__(self, *args, **kwargs):
+        "Override parent constructor to allow 'bus' to be provided."
+        self.bus = kwargs.pop('bus', None)
+        super(PerpetualTimer, self).__init__(*args, **kwargs)
+
     def run(self):
         while True:
             self.finished.wait(self.interval)
             try:
                 self.function(*self.args, **self.kwargs)
             except Exception:
-                self.bus.log("Error in perpetual timer thread function %r." %
-                             self.function, level=40, traceback=True)
+                if self.bus:
+                    self.bus.log(
+                        "Error in perpetual timer thread function %r." %
+                        self.function, level=40, traceback=True)
                 # Quit on first error to avoid massive logs.
                 raise