我正在尝试使用 gevent.server 构建一个基本的 Web 服务器,并且很想知道是否有任何我可以使用的 baseHTTPHandlers。
问问题
1349 次
1 回答
1
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
于 2015-07-11T11:48:37.757 回答