Commits

Robert Brewer  committed b7c3af2

Moved timeout monitor to a new bus channel

  • Participants
  • Parent commits eb5ca91

Comments (0)

Files changed (6)

File py2/cherrypy/__init__.py

 __version__ = "3.2.0"
 
 from cherrypy._cpcompat import urljoin as _urljoin, urlencode as _urlencode
-from cherrypy._cpcompat import basestring, unicodestr
+from cherrypy._cpcompat import basestring, unicodestr, set
 
 from cherrypy._cperror import HTTPError, HTTPRedirect, InternalRedirect
 from cherrypy._cperror import NotFound, CherryPyException, TimeoutError
     engine = process.bus
 
 
-# Timeout monitor
+# Timeout monitor. We add two channels to the engine
+# to which cherrypy.Application will publish.
+engine.listeners['before_request'] = set()
+engine.listeners['after_request'] = set()
+
 class _TimeoutMonitor(process.plugins.Monitor):
     
     def __init__(self, bus):
         self.servings = []
         process.plugins.Monitor.__init__(self, bus, self.run)
     
-    def acquire(self):
+    def before_request(self):
         self.servings.append((serving.request, serving.response))
     
-    def release(self):
+    def after_request(self):
         try:
             self.servings.remove((serving.request, serving.response))
         except ValueError:

File py2/cherrypy/_cptree.py

         
         resp = self.response_class()
         cherrypy.serving.load(req, resp)
-        cherrypy.engine.timeout_monitor.acquire()
         cherrypy.engine.publish('acquire_thread')
+        cherrypy.engine.publish('before_request')
         
         return req, resp
     
         """Release the current serving (request and response)."""
         req = cherrypy.serving.request
         
-        cherrypy.engine.timeout_monitor.release()
+        cherrypy.engine.publish('after_request')
         
         try:
             req.close()

File py2/cherrypy/test/test_caching.py

         self.getPage("/clear_cache?path=" +
             quote('/long_process?seconds=%d' % SECONDS, safe=''))
         self.assertStatus(200)
-        sys.stdout.write("prepped... ")
-        sys.stdout.flush()
         
         start = datetime.datetime.now()
         def run():

File py3/cherrypy/__init__.py

 __version__ = "3.2.0"
 
 from cherrypy._cpcompat import urljoin as _urljoin, urlencode as _urlencode
-from cherrypy._cpcompat import basestring, unicodestr
+from cherrypy._cpcompat import basestring, unicodestr, set
 
 from cherrypy._cperror import HTTPError, HTTPRedirect, InternalRedirect
 from cherrypy._cperror import NotFound, CherryPyException, TimeoutError
     engine = process.bus
 
 
-# Timeout monitor
+# Timeout monitor. We add two channels to the engine
+# to which cherrypy.Application will publish.
+engine.listeners['before_request'] = set()
+engine.listeners['after_request'] = set()
+
 class _TimeoutMonitor(process.plugins.Monitor):
     
     def __init__(self, bus):
         self.servings = []
         process.plugins.Monitor.__init__(self, bus, self.run)
     
-    def acquire(self):
+    def before_request(self):
         self.servings.append((serving.request, serving.response))
     
-    def release(self):
+    def after_request(self):
         try:
             self.servings.remove((serving.request, serving.response))
         except ValueError:

File py3/cherrypy/_cptree.py

         
         resp = self.response_class()
         cherrypy.serving.load(req, resp)
-        cherrypy.engine.timeout_monitor.acquire()
         cherrypy.engine.publish('acquire_thread')
+        cherrypy.engine.publish('before_request')
         
         return req, resp
     
         """Release the current serving (request and response)."""
         req = cherrypy.serving.request
         
-        cherrypy.engine.timeout_monitor.release()
+        cherrypy.engine.publish('after_request')
         
         try:
             req.close()

File py3/cherrypy/test/test_caching.py

         self.getPage("/clear_cache?path=" +
             quote('/long_process?seconds=%d' % SECONDS, safe=''))
         self.assertStatus(200)
-        sys.stdout.write("prepped... ")
-        sys.stdout.flush()
         
         start = datetime.datetime.now()
         def run():