I have an existing cherrypy application but I want to know is if it's at all possible to run it on the gevent wsgi server. I imagine I can but I don't have access to a linux server to test out gevent and haven't been able to get it to run on my mac.
I'm under the impression this is possible since each side follows wsgi spec.
Has anyone tried this?
I guess an example would look like the following:
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()
This example will work until you encounter greenlet switch inside cherrypy handlers ! So this will fail if you use gevent for asynchronous communication inside handlers.
cherrypy uses global object for storing response and headers inside found inside 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')
If you pause one request and gevent switches to processing next it will overwrite content-length header in global object and you will face strange errors on client side.
That example works fine. I'm sure #gevent on freenode would help you with any installation issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With