我正在尝试使用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