Robert Brewer  committed dbced17

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.

  • Participants
  • Parent commits 4d848dc
  • Branches default

Comments (0)

Files changed (1)

File cherrypy/

+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."""
         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")
         if blocking:
             if self.monitor_thread:
+                self.monitor_thread.join()
                 self.monitor_thread = None
             self.state = STOPPED
         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:
-        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."""