【问题标题】:Grafting WSGI app on CherryPy via configuration file通过配置文件在 CherryPy 上移植 WSGI 应用
【发布时间】:2019-04-25 08:41:58
【问题描述】:

我的 CherryPy 服务器中嵌入(移植)了一个 WSGI 应用程序。

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()

其中server.conf 是定义服务器属性等的静态配置文件。

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

现在我想使用 cherryd 实用程序将 CherryPy 作为守护程序服务运行,因此我应该将代码中的嫁接部分转换为静态配置。

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

我找不到这方面的工作示例,但显然不行:

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

当我尝试启动它时:

$ cherryd -c server.conf -i my_app

想法?

【问题讨论】:

    标签: wsgi cherrypy


    【解决方案1】:

    解决办法是:

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

    无论如何,我是从this 问题中猜到的。我不确定 CherryPy 文档中的某个点我可以看到这个。


    阅读 Bernd Haug 的回答 here 后,我意识到 tree.graft(value) 转换为 cherrypy._cpconfig._tree_config_handler("graft", value),是第一个“移植”只是一个任意标签。我可以打电话给 tree.foo 并且仍然在后台(如果 Bern Haug 是正确的),我实际上是 cherrypy.tree.graft-ing WSGI 应用程序。

    【讨论】:

      猜你喜欢
      • 2011-01-21
      • 1970-01-01
      • 2014-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-16
      • 1970-01-01
      相关资源
      最近更新 更多