Commits

Robert Brewer committed 707501c

Moved all bus plugins onto the engine object itself, and fixed a couple bus details along the way.

Comments (0)

Files changed (10)

cherrypy/__init__.py

 try:
     from cherrypy.process import win32
     engine = win32.Win32Bus()
-    _console_control_handler = win32.ConsoleCtrlHandler(engine)
-    # If you don't want a ConsoleControlHandler,
-    # unsubscribe this before calling engine.start().
-    _console_control_handler.subscribe()
+    engine.console_control_handler = win32.ConsoleCtrlHandler(engine)
     del win32
 except ImportError:
     engine = process.bus
         """Check timeout on all responses. (Internal)"""
         for req, resp in self.servings:
             resp.check_timeout()
-timeout_monitor = _TimeoutMonitor(engine)
-timeout_monitor.subscribe()
+engine.timeout_monitor = _TimeoutMonitor(engine)
+engine.timeout_monitor.subscribe()
 
-# Add an autoreloader (the 'engine' config namespace may detach/attach it).
 engine.autoreload = process.plugins.Autoreloader(engine)
 engine.autoreload.subscribe()
 
-process.plugins.ThreadManager(engine).subscribe()
+engine.thread_manager = process.plugins.ThreadManager(engine)
+engine.thread_manager.subscribe()
 
-signal_handler = process.plugins.SignalHandler(engine)
+engine.signal_handler = process.plugins.SignalHandler(engine)
+
 
 from cherrypy import _cpserver
 server = _cpserver.Server()
     if root is not None:
         tree.mount(root, script_name, config)
     
-    signal_handler.subscribe()
+    if hasattr(engine, "signal_handler"):
+        engine.signal_handler.subscribe()
+    if hasattr(engine, "console_control_handler"):
+        engine.console_control_handler.subscribe()
+    
     engine.start()
     engine.block()
 

cherrypy/_cpconfig.py

     elif k == 'reload_files':
         engine.autoreload.files = v
     elif k == 'deadlock_poll_freq':
-        cherrypy.timeout_monitor.frequency = v
+        engine.timeout_monitor.frequency = v
     elif k == 'SIGHUP':
         engine.listeners['SIGHUP'] = set([v])
     elif k == 'SIGTERM':

cherrypy/_cpmodpy.py

     cherrypy.config.update({'environment': 'production',
                             'log.screen': False,
                             'show_tracebacks': False})
-    
-    # Turn off the builtin signal handlers, which can interact
-    # in strange ways with the Apache process.
-    cherrypy.engine.SIGHUP = None
-    cherrypy.engine.SIGTERM = None
-    
-    # You must start the engine in a non-blocking fashion
-    # so that mod_python can proceed
-    cherrypy.engine.start()
 
 ##########################################
 # mod_python settings for apache2
                             "tools.ignore_headers.headers": ['Range'],
                             })
     
-    if hasattr(cherrypy, '_console_control_handler'):
-        cherrypy._console_control_handler.unsubscribe()
-    cherrypy.engine.autoreload.unsubscribe()
+    engine = cherrypy.engine
+    if hasattr(engine, "signal_handler"):
+        engine.signal_handler.unsubscribe()
+    if hasattr(engine, "console_control_handler"):
+        engine.console_control_handler.unsubscribe()
+    engine.autoreload.unsubscribe()
     cherrypy.server.unsubscribe()
     
     def _log(msg, level):
         # http://www.modpython.org/pipermail/mod_python/2003-October/014291.html.
         # Also, "When server is not specified...LogLevel does not apply..."
         apache.log_error(msg, newlevel, req.server)
-    cherrypy.engine.subscribe('log', _log)
+    engine.subscribe('log', _log)
     
-    cherrypy.engine.start()
+    engine.start()
     
     def cherrypy_cleanup(data):
-        cherrypy.engine.exit()
+        engine.exit()
     try:
         # apache.register_cleanup wasn't available until 3.1.4.
         apache.register_cleanup(cherrypy_cleanup)

cherrypy/_cptree.py

         
         resp = self.response_class()
         cherrypy.serving.load(req, resp)
-        cherrypy.timeout_monitor.acquire()
+        cherrypy.engine.timeout_monitor.acquire()
         cherrypy.engine.publish('acquire_thread')
         
         return req, resp
         """Release the current serving (request and response)."""
         req = cherrypy.serving.request
         
-        cherrypy.timeout_monitor.release()
+        cherrypy.engine.timeout_monitor.release()
         
         try:
             req.close()
     if pidfile:
         plugins.PIDFile(engine, pidfile).subscribe()
     
-    cherrypy.signal_handler.subscribe()
+    if hasattr(engine, "signal_handler"):
+        engine.signal_handler.subscribe()
+    if hasattr(engine, "console_control_handler"):
+        engine.console_control_handler.subscribe()
     
     if fastcgi:
         # turn off autoreload when using fastcgi

cherrypy/process/plugins.py

                 self.thread = PerpetualTimer(self.frequency, self.callback)
                 self.thread.setName(threadname)
                 self.thread.start()
-                self.bus.log("Started thread %r." % threadname)
+                self.bus.log("Started monitor thread %r." % threadname)
             else:
-                self.bus.log("Thread %r already started." % threadname)
+                self.bus.log("Monitor thread %r already started." % threadname)
     start.priority = 70
     
     def stop(self):

cherrypy/process/win32.py

     
     def start(self):
         if self.is_set:
+            self.bus.log('Handler for console events already set.', level=40)
             return
         
         result = win32api.SetConsoleCtrlHandler(self.handle, 1)
             self.bus.log('Could not SetConsoleCtrlHandler (error %r)' %
                          win32api.GetLastError(), level=40)
         else:
+            self.bus.log('Set handler for console events.', level=40)
             self.is_set = True
     
     def stop(self):
         if not self.is_set:
+            self.bus.log('Handler for console events already off.', level=40)
             return
         
         try:
             self.bus.log('Could not remove SetConsoleCtrlHandler (error %r)' %
                          win32api.GetLastError(), level=40)
         else:
+            self.bus.log('Removed handler for console events.', level=40)
             self.is_set = False
     
     def handle(self, event):

cherrypy/process/wspbus.py

         self.state = states.EXITING
         self.log('Bus EXITING')
         self.publish('exit')
+        # This isn't strictly necessary, but it's better than seeing
+        # "Waiting for child threads to terminate..." and then nothing.
+        self.log('Bus EXITED')
     
     def restart(self):
         """Restart the process (may close connections).

cherrypy/test/helper.py

     """
     cherrypy.config.reset()
     setConfig(conf)
-    cherrypy.signal_handler.subscribe()
+    engine = cherrypy.engine
+    if hasattr(engine, "signal_handler"):
+        engine.signal_handler.subscribe()
+    if hasattr(engine, "console_control_handler"):
+        engine.console_control_handler.subscribe()
     # The Pybots automatic testing system needs the suite to exit
     # with a non-zero value if there were any problems.
     # Might as well stick it in the engine... :/
-    cherrypy.engine.test_success = True
-    cherrypy.engine.start_with_callback(_run_test_suite_thread,
-                                        args=(moduleNames, conf))
-    cherrypy.engine.block()
-    if cherrypy.engine.test_success:
+    engine.test_success = True
+    engine.start_with_callback(_run_test_suite_thread,
+                               args=(moduleNames, conf))
+    engine.block()
+    if engine.test_success:
         return 0
     else:
         return 1

cherrypy/test/test_states.py

         engine.start()
         cherrypy.server.start()
         try:
-            self.assertNotEqual(cherrypy.timeout_monitor.thread, None)
+            self.assertNotEqual(engine.timeout_monitor.thread, None)
             
             # Request a "normal" page.
-            self.assertEqual(cherrypy.timeout_monitor.servings, [])
+            self.assertEqual(engine.timeout_monitor.servings, [])
             self.getPage("/")
             self.assertBody("Hello World")
             # request.close is called async.
-            while cherrypy.timeout_monitor.servings:
+            while engine.timeout_monitor.servings:
                 print ".",
                 time.sleep(0.01)
             
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.