Unterstanding eventlet.wsgi.server

送分小仙女□ 提交于 2020-01-02 09:56:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!