django - 在 Django View 执行上设置超时

标签 django django-views

如何设置执行 Django View 的时间限制。也就是说,一个 View 的执行时间永远不会超过 10 秒,如果是,它应该从执行中途返回。我的想法是我们可以有一个装饰器。但我不确定。寻找解决方案。提前致谢。

最佳答案

我建议考虑使用 Celery,它内置了 time limit support用于任务,并使您的 Django 应用程序和服务器保持响应:

A single task can potentially run forever, if you have lots of tasks waiting for some event that will never happen you will block the worker from processing new tasks indefinitely. The best way to defend against this scenario happening is enabling time limits.

关于django - 在 Django View 执行上设置超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10118098/

相关文章:

django - 扩展 Django 的通用 View

django - 如何在Django中设置cookie然后渲染模板?

Django channel 在本地工作但不在服务器上工作,WebSocket 握手期间出错

python - 如何在 Django 中获取登录用户 ID

python - Django Post.objects.all() 不显示对象属性

django - PyCharm:自动插入 Django 模板结束标签( {% endif %} {% endfor %} 等)选项?

django如何创建字段相关字段

python - Django - feeds() 处的 TypeError 缺少 1 个必需的位置参数 : 'id'

python - 在 Django View 中结合 modelformset 和 inlineformset

Django Server 不影响 View 变化