私はcherrypy.quickstartの代わりにcherrypy.engine.startでcherrypyを実行しようとしています。これは、cherrypy を非ブロッキング状態で実行して、py.test を使用した機能テスト内で Web サーバーを開始および停止したいためです。
これはうまくいきます:
cherrypy.quickstart(WebServerTest(None), config=testconf)
curl に対する応答は次のとおりです。
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 に対する応答は次のとおりです。
curl --head http://127.0.0.1:1026/index
curl: (7) couldn't connect to host
cherrypy.engine.block() aftet cherrypy.engine.start を追加しても問題は解決しません。
では、cherrypy.engine.start() で動作させるにはどうすればよいでしょうか?
webservertest.conf 構成ファイルは次のとおりです。
[global]
server.socket_host = "127.0.0.1"
server.socket_port = 1026
server.thread_pool = 10