我有一个现有的cherrypy应用程序,但我想知道是否可以在gevent wsgi服务器上运行它。我想我可以,但我无法访问linux服务器来测试gevent,也无法让它在我的mac上运行。
我的印象是这是可能的,因为每一方都遵循wsgi规范。
有人试过这个吗?
我猜一个示例如下所示:
import cherrypy
from gevent import wsgi
class Root(object):
def index(self):
return "hi!"
index.exposed = True
app = cherrypy.tree.mount(Root(), '/')
wsgi.WSGIServer(('', 8088), app).serve_forever()
发布于 2011-03-01 05:32:25
这个例子运行得很好。我相信#gevent on freenode会帮助你解决任何安装问题。
发布于 2012-06-06 23:18:20
这个示例将一直有效,直到您在cherrypy处理程序中遇到greenlet switch为止!因此,如果您使用gevent在处理程序内部进行异步通信,则此操作将失败。
cherrypy使用全局对象来存储响应和在cherrypy/__ init__.py:~350中找到的报头:
# Create request and response object (the same objects will be used
# throughout the entire life of the webserver, but will redirect
# to the "serving" object)
request = _ThreadLocalProxy('request')
response = _ThreadLocalProxy('response')
如果您暂停一个请求,gevent切换到下一个处理,它将覆盖全局对象中的content-length报头,并且您将在客户端遇到奇怪的错误。
https://stackoverflow.com/questions/5073499
复制相似问题