Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is sleep() blocking the handling of requests in Django?

Tags:

python

django

In Django, if the view uses a sleep() function while answering a request, does this block the handling of the whole queue of requests?

If so, how to delay an http answer without this blocking behavior? Can we do that out-of-the-box and avoid using a job queue like Celeri?

like image 388
Zack4 Avatar asked Nov 03 '22 13:11

Zack4


1 Answers

I would image that calling sleep() should block the execution of all Django code in most cases. However it might depend on the deployment architecture (e.g. gevent, gunicorn, etc). For instance if you are using a server which fires Django threads for each request, then no it will not block all the code.

In most cases however using something like Celeri would like to be a much better solution because (1) don't reinvent the wheel and (2) it has been tested.

like image 119
miki725 Avatar answered Nov 15 '22 04:11

miki725