Async worker on gunicorn seems blocking

巧了我就是萌 提交于 2019-12-03 06:26:14

问题


I am using a Flask app with the gunicorn server and the gevent worker class, which according to the gunicorn documentation is an asynchronous worker. However, when I launch gunicorn with a single worker and try to make a long request (I added sleep(10) in the route function, but in reality this also happens when processing large uploads), I can't make any request until the previous one is finished. It behaves as is it is a synchronous worker, one request at a time.

Is this the normal behavior? Am I missing something about synchronous vs asynchronous workers?


回答1:


If you don't monkey-patch sleep (or use gevent's non-blocking version of sleep) then a worker that blocks blocks the entire event loop.

Either call gevent.monkey.patch_all (or more specifically gevent.monkey.patch_time) or replace your call to time.sleep with gevent.sleep



来源:https://stackoverflow.com/questions/29527351/async-worker-on-gunicorn-seems-blocking

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