Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running cherrypy application on gevent wsgi server

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()
like image 279
deecodameeko Avatar asked Feb 22 '11 02:02

deecodameeko


2 Answers

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.

like image 182
Alex Avatar answered Oct 12 '22 09:10

Alex


That example works fine. I'm sure #gevent on freenode would help you with any installation issues.

like image 44
tmc Avatar answered Oct 12 '22 08:10

tmc