summaryrefslogtreecommitdiff
path: root/cherrypy/process/plugins.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2012-11-07 08:13:55 -0700
committerJason R. Coombs <jaraco@jaraco.com>2012-11-07 08:13:55 -0700
commit3fc6e63e05a0b534a14d99ca98e6acd08cfe2cdf (patch)
tree0c7153b96d8b74649a2b287e74c945f0d4173568 /cherrypy/process/plugins.py
parenta5aec27b5ed05d621a1f7d1b7cc2154961900ff1 (diff)
downloadcherrypy-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.py13
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