diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2012-11-07 08:13:55 -0700 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2012-11-07 08:13:55 -0700 |
commit | 3fc6e63e05a0b534a14d99ca98e6acd08cfe2cdf (patch) | |
tree | 0c7153b96d8b74649a2b287e74c945f0d4173568 /cherrypy/process/plugins.py | |
parent | a5aec27b5ed05d621a1f7d1b7cc2154961900ff1 (diff) | |
download | cherrypy-git-3fc6e63e05a0b534a14d99ca98e6acd08cfe2cdf.tar.gz |
Override constructor in Perpetual to allow 'bus' parameter to be given.
Check for presence of bus parameter when reporting exceptions in PerpetualTimer. Fixes #1183.
--HG--
branch : cherrypy-3.2.x
Diffstat (limited to 'cherrypy/process/plugins.py')
-rw-r--r-- | cherrypy/process/plugins.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/cherrypy/process/plugins.py b/cherrypy/process/plugins.py index 32a0c7e0..eee138fd 100644 --- a/cherrypy/process/plugins.py +++ b/cherrypy/process/plugins.py @@ -422,13 +422,18 @@ class PIDFile(SimplePlugin): 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) @@ -437,8 +442,10 @@ class PerpetualTimer(Timer): 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 |