I am trying to build a basic web server using gevent.server, and curious to know is there any baseHTTPHandlers, I can use.
Asked
Active
Viewed 1,550 times
1 Answers
2
Yes, gevent comes with two HTTP server implementations you can use:
gevent.wsgi - fast, libevent-based implementation, but providing limited features.
gevent.pywsgi - slower, pure gevent implementation, but providing more features (streaming, pipelining, SSL).
Here is a simple example (extracted from gevent documentation):
#!/usr/bin/python
"""WSGI server example"""
from __future__ import print_function
from gevent.pywsgi import WSGIServer
def application(env, start_response):
if env['PATH_INFO'] == '/':
start_response('200 OK', [('Content-Type', 'text/html')])
return [b"<b>hello world</b>"]
else:
start_response('404 Not Found', [('Content-Type', 'text/html')])
return [b'<h1>Not Found</h1>']
if __name__ == '__main__':
print('Serving on 8088...')
WSGIServer(('', 8088), application).serve_forever()
For more information, see http://www.gevent.org/servers.html
See also http://blog.pythonisito.com/2012/08/building-web-applications-with-gevents.html

Didier Spezia
- 70,911
- 12
- 189
- 154