问题
I have this simple Python programm:
from eventlet import wsgi
import eventlet
from eventlet.green import time
def hello_world(env, start_response):
print "got request"
time.sleep(10)
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['Hello, World!\n']
wsgi.server(eventlet.listen(('', 8090)), hello_world)
So when i run it, and open http://localhost:8090/
on my browser multiple times, got request
is only printed after the first request was already processed (after 10 seconds).
It seems like eventlet.wsgi.server
is processing the requests synchronously. But I am using the "green" sleep
. sow how can this happen?
Thank you!
回答1:
You have to use the monkey patch as below:
eventlet.patcher.monkey_patch(all=False, socket=True, time=True,
select=True, thread=True, os=True)
More information could be found from this link.
来源:https://stackoverflow.com/questions/8509209/unterstanding-eventlet-wsgi-server