@oberstet is right. This is a quick showcase on how to run a CherryPy app:
import cherrypy
from twisted.web.wsgi import WSGIResource
from twisted.internet import reactor
# Our CherryPy application
class Root(object):
@cherrypy.expose
def index(self):
return "hello world"
# Create our WSGI app from the CherryPy application
# it will respond to the /blog path
wsgiapp = cherrypy.tree.mount(Root(), '/blog', {'/': {'tools.etags.on': True}})
# 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()
# 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)
Assuming you save this snippet into a module called: "cptw.py", you can now serve your CherryPy application as follow:
twistd -n web --wsgi cptw.wsgiapp
This works with Twisted 13.2 and CherryPy 3.2.6+