Cherrypy.tree.mount and mod_wsgi

I used cherrypy with mod_python, and I built controller trees with calls to cherrypy.tree.mount , and I would like to save them (they are distributed through the code). Now I have to use mod_wsgi. Example: from cherry wiki

 import sys sys.stdout = sys.stderr import atexit import threading import cherrypy cherrypy.config.update({'environment': 'embedded'}) if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0: cherrypy.engine.start(blocking=False) atexit.register(cherrypy.engine.stop) class Root(object): def index(self): return 'Hello World!' index.exposed = True application = cherrypy.Application(Root(), script_name=None, config=None) 

My problem is that every call to cherrypy.tree.mount creates cherrypy.Application . And mod_wsgi wants a single object named 'application' .

I know that you can build a cherry tree with class variables, but I don't want to do this.

Is there a way to use cherrypy.tree.mount and get one application object?

There is also cherrypy.tree.graft , but I think it meant for another purpose.

+4
source share
1 answer

Finally! Got it myself - from the manual ...

cherrypy.tree itself is a WSGI object, so you just do:

 cherrypy.tree.mount(...) cherrypy.tree.mount(...) cherrypy.tree.mount(...) application = cherrypy.tree 
+9
source

Source: https://habr.com/ru/post/1336827/


All Articles