简体   繁体   English

sleep()是否阻止Django中的请求处理?

[英]Is sleep() blocking the handling of requests in 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? 在Django中,如果视图在回答请求时使用了sleep()函数,这是否会阻塞整个请求队列的处理?

If so, how to delay an http answer without this blocking behavior? 如果是这样,如何在没有这种阻止行为的情况下延迟http回答? Can we do that out-of-the-box and avoid using a job queue like Celeri? 我们可以立即执行此操作并避免使用像Celeri这样的作业队列吗?

I would image that calling sleep() should block the execution of all Django code in most cases. 我想像一下,在大多数情况下,调用sleep()应该会阻止所有Django代码的执行。 However it might depend on the deployment architecture (eg gevent, gunicorn, etc). 但是,这可能取决于部署架构(例如gevent,gunicorn等)。 For instance if you are using a server which fires Django threads for each request, then no it will not block all the code. 例如,如果您使用的服务器为每个请求触发Django线程,则否,它将不会阻止所有代码。

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. 但是,在大多数情况下,使用Celele之类的方法可能会是更好的解决方案,因为(1)不会重新发明轮子,并且(2)它已经过测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM