Commits

Anonymous committed 2bac386

ticket #53 (still need some testing for it)

Comments (0)

Files changed (2)

cherrypy/_cphttpserver.py

     _cpLogMessage("Serving %s on %s" % (servingWhat, onWhat), 'HTTP')
 
     try:
+        # Call the functions from cpg.server.onStartServerList
+        for func in cpg.server.onStartServerList:
+            func()
         myCherryHTTPServer.serve_forever()
     except KeyboardInterrupt:
         _cpLogMessage("<Ctrl-C> hit: shutting down", "HTTP")
         myCherryHTTPServer.shutdown()
-
+    # Call the functions from cpg.server.onStartServerList
+    for func in cpg.server.onStopServerList:
+        func()
 
 class CherryHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
 
         self._threadIndex = threadIndex
         
     def run(self):
-        _cputil.getSpecialFunction('_cpInitThread')(self._threadIndex)
+        # Call the functions from cpg.server.onStartThreadList
+        for func in cpg.server.onStartThreadList:
+            func()
         while 1:
             request, client_address = self._requestQueue.get()
             if (request, client_address) == _SHUTDOWNREQUEST:
+                # Call the functions from cpg.server.onStopThreadList
+                for func in cpg.server.onStopThreadList:
+                    func()
                 return
             if self.verify_request(request, client_address):            
                 try:

cherrypy/_cpserver.py

 def stop():
     _cphttpserver.stop()
 
+# Set some special attributes for adding hooks
+onStartServerList = []
+onStartThreadList = []
+onStopServerList = []
+onStopThreadList = []