Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Async worker on gunicorn seems blocking

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?

like image 954
Romain Paulus Avatar asked Apr 08 '15 23:04

Romain Paulus


1 Answers

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

like image 50
Sean Vieira Avatar answered Sep 17 '22 08:09

Sean Vieira