Unterstanding eventlet.wsgi.server

2019-05-26 07:02发布

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条回答
Evening l夕情丶
2楼-- · 2019-05-26 07:35

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.

查看更多
登录 后发表回答