diff options
author | Robert Brewer <fumanchu@aminus.org> | 2006-11-18 18:44:48 +0000 |
---|---|---|
committer | Robert Brewer <fumanchu@aminus.org> | 2006-11-18 18:44:48 +0000 |
commit | 58ceaff36063fc18a948253c3f61e4a272cbdc93 (patch) | |
tree | 8bc10719838f7863655d95650f3239a8c9939dd4 /cherrypy/_cpengine.py | |
parent | e6a377dd229147e700043eb3e50a4f13d7e666f5 (diff) | |
download | cherrypy-git-58ceaff36063fc18a948253c3f61e4a272cbdc93.tar.gz |
Engine.stop was calling monitor_thread.cancel() but not .join(). Engine.monitor_thread is also now a PerpetualTimer, so it keeps the same thread rather than spawning new ones on each run.
Diffstat (limited to 'cherrypy/_cpengine.py')
-rw-r--r-- | cherrypy/_cpengine.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/cherrypy/_cpengine.py b/cherrypy/_cpengine.py index 11558f3d..44d88062 100644 --- a/cherrypy/_cpengine.py +++ b/cherrypy/_cpengine.py @@ -32,6 +32,16 @@ except ValueError, _signal_exc: raise +class PerpetualTimer(threading._Timer): + + def run(self): + while True: + self.finished.wait(self.interval) + if self.finished.isSet(): + return + self.function(*self.args, **self.kwargs) + + class Engine(object): """Application interface for (HTTP) servers, plus process controls.""" @@ -71,7 +81,8 @@ class Engine(object): freq = self.deadlock_poll_freq if freq > 0: - self.monitor_thread = threading.Timer(freq, self.monitor) + self.monitor_thread = PerpetualTimer(freq, self.monitor) + self.monitor_thread.setName("CPEngine Monitor") self.monitor_thread.start() if blocking: @@ -162,6 +173,7 @@ class Engine(object): if self.monitor_thread: self.monitor_thread.cancel() + self.monitor_thread.join() self.monitor_thread = None self.state = STOPPED @@ -211,13 +223,10 @@ class Engine(object): return req def monitor(self): - """Check timeout on all responses (starts a recurring Timer thread).""" + """Check timeout on all responses.""" if self.state == STARTED: for req, resp in self.servings: resp.check_timeout() - freq = self.deadlock_poll_freq - self.monitor_thread = threading.Timer(freq, self.monitor) - self.monitor_thread.start() def start_with_callback(self, func, args=None, kwargs=None): """Start the given func in a new thread, then start self and block.""" |