Commits

Eric Larson  committed 936794a

Add (via monkeypatch) a handle_signals function to the engine.

The quickstart typically would do some checks to see what platform it
is on and add handlers to correctly accept signals via other
processes. This ecapulates those tests and adding the handlers to the
engine. The result being you can easily replicate quickstart without
the mounting aspects by running:

cherrypy.engine.handle_signals()
cherrypy.engine.start()
cherrypy.engine.block()

  • Participants
  • Parent commits a2c05b8

Comments (0)

Files changed (1)

File cherrypy/__init__.py

 engine.signal_handler = process.plugins.SignalHandler(engine)
 
 
+def _handle_signals():
+    """
+    Allow the engine to properly handle signals on all
+    platforms.
+    """
+    if hasattr(engine, "signal_handler"):
+        engine.signal_handler.subscribe()
+    if hasattr(engine, "console_control_handler"):
+        engine.console_control_handler.subscribe()
+
+engine.handle_signals = _handle_signals
+
+
 from cherrypy import _cpserver
 server = _cpserver.Server()
 server.subscribe()
 
     tree.mount(root, script_name, config)
 
-    if hasattr(engine, "signal_handler"):
-        engine.signal_handler.subscribe()
-    if hasattr(engine, "console_control_handler"):
-        engine.console_control_handler.subscribe()
-
+    engine.handle_signals()
     engine.start()
     engine.block()