summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLawouach <sh@defuze.org>2014-04-27 22:12:48 +0200
committerLawouach <sh@defuze.org>2014-04-27 22:12:48 +0200
commitb598698ad3537f77e609cb2f0bb312fe095b9e3f (patch)
tree16d109add0f323172a50cc2bb20ec265fcb985bc
parent82b2c568a8f00cd005d8387cb9b158ada2f4e359 (diff)
downloadcherrypy-b598698ad3537f77e609cb2f0bb312fe095b9e3f.tar.gz
publish to the 'main' channel
-rw-r--r--sphinx/source/deploy.rst38
1 files changed, 21 insertions, 17 deletions
diff --git a/sphinx/source/deploy.rst b/sphinx/source/deploy.rst
index 40233e34..ff4905a4 100644
--- a/sphinx/source/deploy.rst
+++ b/sphinx/source/deploy.rst
@@ -67,8 +67,10 @@ follow:
.. code-block:: python
import cherrypy
+
from twisted.web.wsgi import WSGIResource
from twisted.internet import reactor
+ from twisted.internet import task
# Our CherryPy application
class Root(object):
@@ -76,28 +78,30 @@ follow:
def index(self):
return "hello world"
- if __name__ == '__main__':
- # Create our WSGI app from the CherryPy application
- wsgiapp = cherrypy.tree.mount(Root())
+ # Create our WSGI app from the CherryPy application
+ wsgiapp = cherrypy.tree.mount(Root())
- # Configure the CherryPy's app server
- # Disable the autoreload which won't play well
- cherrypy.config.update({'engine.autoreload.on': False})
+ # Configure the CherryPy's app server
+ # Disable the autoreload which won't play well
+ cherrypy.config.update({'engine.autoreload.on': False})
- # We will be using Twisted HTTP server so let's
- # disable the CherryPy's HTTP server entirely
- cherrypy.server.unsubscribe()
+ # We will be using Twisted HTTP server so let's
+ # disable the CherryPy's HTTP server entirely
+ cherrypy.server.unsubscribe()
- # If you'd rather use CherryPy's signal handler
- # Uncomment the next line. I don't know how well this
- # will play with Twisted however
- #cherrypy.engine.signals.subscribe()
+ # If you'd rather use CherryPy's signal handler
+ # Uncomment the next line. I don't know how well this
+ # will play with Twisted however
+ #cherrypy.engine.signals.subscribe()
- # Tie our app to Twisted
- reactor.addSystemEventTrigger('after', 'startup', cherrypy.engine.start)
- reactor.addSystemEventTrigger('before', 'shutdown', cherrypy.engine.exit)
- resource = WSGIResource(reactor, reactor.getThreadPool(), wsgiapp)
+ # Publish periodically onto the 'main' channel as the bus mainloop would do
+ task.LoopingCall(lambda: cherrypy.engine.publish('main')).start(0.1)
+ # Tie our app to Twisted
+ reactor.addSystemEventTrigger('after', 'startup', cherrypy.engine.start)
+ reactor.addSystemEventTrigger('before', 'shutdown', cherrypy.engine.exit)
+ resource = WSGIResource(reactor, reactor.getThreadPool(), wsgiapp)
+
Notice how we attach the bus methods to the Twisted's own lifecycle.
Save that code into a module named `cptw.py` and run it as follow: