Commits

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.

Comments (0)

Files changed (1)

cherrypy/_cpengine.py

         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."""
     
         
         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:
             
             if self.monitor_thread:
                 self.monitor_thread.cancel()
+                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:
                 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."""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.