本文介绍了在gunicorn异步工作者似乎阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gunicorn服务器和gevent工人类的Flask应用程序,它根据是一个异步工作者。然而,当我用一个工作人员启动gunicorn并尝试做一个长时间的请求(我在路由功能中加入了 sleep(10)),但实际上这也发生在处理大量上传),直到前一个完成后才能发出请求。它的行为就像它是一个同步工作者,一次一个请求。



这是正常行为吗?我错过了关于同步和异步工作者的一些事情吗?

(或使用 gevent 的的非阻塞版本),那么阻止的工作者将阻止整个事件循环。 >

请拨打(或者更具体的)将您的呼叫替换为 time.sleep with


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?

解决方案

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

这篇关于在gunicorn异步工作者似乎阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 20:18