Reputation: 2368
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?
Upvotes: 8
Views: 4236
Reputation: 159855
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
Upvotes: 11