As shown in this page https://pypi.python.org/pypi/gevent-fastcgi, we can use gevent-fastcgi in stand-alone mode.
from gevent_fastcgi.server import FastCGIServer
from gevent_fastcgi.wsgi import WSGIRequestHandler
def wsgi_app(environ, start_response):
start_response('200 OK', [('Content-type', 'text/plain')])
yield 'Hello World!'
request_handler = WSGIRequestHandler(wsgi_app)
server = FastCGIServer(('127.0.0.1', 4000), request_handler, num_workers=4)
server.serve_forever()
However, when I tried it with wget, it get blocked.
$ wget http://127.0.0.1:4000/ping
Connecting to 127.0.0.1:4000... connected.
HTTP request sent, awaiting response...
Python2.7.10, gevent-fastcgi==1.0.2.1, gevent==1.2.1
Is there anything wrong with the code? Thanks
gevent-fastcgi
is a library to serve WSGI app via fastcgi protocol, but wget
is trying to talk with HTTP, you need another server in front of "127.0.0.1:4000" to translate HTTP to fastcgi, like nginx.