0

I have a WSGI app embedded (grafted) in my CherryPy server.

from my_app import application
import cherrypy

if __name__ == '__main__':

    cherrypy.config.update("server.conf")
    cherrypy.tree.graft(application, "/good_stuff/")

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

Where server.conf is the static configuration file which defines the server properties and so on.

[global]                                                  
server.socket_host = "0.0.0.0"
server.socket_port = 8087
server.thread_pool = 30

Now I would like to run CherryPy as a daemon service my using the cherryd utility, so I should turn the grafting part in the code to static configuration.

[global]
...
tree.graft = {my_app.application:"/good_stuff/"}

I couldn't find working examples on this, but it is clearly not OK:

AttributeError: 'ReloaderApp' object has no attribute 'rstrip'

as I try to launch it:

$ cherryd -c server.conf -i my_app

Ideas?

Campa
  • 4,267
  • 3
  • 37
  • 42

1 Answers1

0

Solution is:

    [global]
    ...
--- tree.graft = {my_app.application:"/good_stuff"}
+++ tree.graft = {"/good_stuff":my_app.application}

In any case, I guessed it from this question. I am not sure there is some point in the CherryPy docs where I could see this.


After reading Bernd Haug's answer here, I realized that the tree.graft(value) translates to cherrypy._cpconfig._tree_config_handler("graft", value), being the first "graft" just an arbitrary label. I could call tree.foo and still under the hood (if Bern Haug is right), I am actually cherrypy.tree.graft-ing the WSGI app.

Campa
  • 4,267
  • 3
  • 37
  • 42