【问题标题】:Non blocking CherryPy does not receive anything非阻塞 CherryPy 没有收到任何东西
【发布时间】:2013-08-08 13:33:35
【问题描述】:

我正在尝试使用cherrypy.engine.start 而不是cherrypy.quickstart 来运行cherrypy。那是因为我想在非阻塞状态下运行cherrypy,以便在我的功能测试中使用 py.test 启动和停止 Web 服务器。

这很好用:

cherrypy.quickstart(WebServerTest(None), config=testconf)

对卷曲的响应是:

curl --head http://127.0.0.1:1026/index HTTP/1.1 200 OK
    Date: Thu, 08 Aug 2013 12:54:37 GMT
    Content-Length: 0
    Content-Type: text/html;charset=utf-8
    Server: CherryPy/3.2.2

但它会阻止脚本的其余部分执行。

但这不起作用:

testconf = path.join(path.dirname(__file__), 'webservertest.conf')
web_server = WebServerTest(None)
cherrypy.tree.mount(web_server, "", config=testconf)
cherrypy.engine.start()
time.sleep(60)
cherrypy.engine.stop()

对卷曲的响应是:

curl --head http://127.0.0.1:1026/index
    curl: (7) couldn't connect to host


在cherrypy.engine.start 之后添加cherrypy.engine.block() 并不能解决问题。


那么我怎样才能让它与cherrypy.engine.start()一起工作呢?


webservertest.conf 配置文件是:

[global]
server.socket_host = "127.0.0.1"
server.socket_port = 1026
server.thread_pool = 10

【问题讨论】:

    标签: python webserver cherrypy


    【解决方案1】:

    您还需要将 conf 传递给cherrypy.config.update(conf)。这是用于全局配置(包括您的服务器主机和端口),而 tree.mount 调用仅设置该特定应用程序的配置。阅读quickstart的源代码,了解所有血腥细节。

    【讨论】:

    • 就是这样!只需添加:cherrypy.config.update(testconf) 就可以了!非常感谢!
    猜你喜欢
    • 2016-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-01
    • 2013-10-03
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    相关资源
    最近更新 更多