【发布时间】: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
【问题讨论】: