本文介绍了如何为Django Rest HTTP请求设置超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python 3.5,Django 1.9.5和Django Rest Framework 3.3.3.我的服务器上只有几个POST api.

I am using Python 3.5, Django 1.9.5 and Django Rest Framework 3.3.3. I have only few POST apis in my server.

如何为每个其余的http请求设置超时,如果对一个请求的执行花费的时间超过3分钟,则它应该返回超时作为响应并应停止执行该请求.

How can I set Timeout for each rest http request that if the execution for a request takes more then 3 minutes than it should return timeout in response and should stop execution of that request.

谢谢:)

推荐答案

我认为您需要在代理/Web服务器级别进行设置.

I think you will need to set this at the proxy/web server level.

使用nginx,您可以使用 proxy_read_timeout :

With nginx you can use proxy_read_timeout:

proxy_read_timeout 180s;

或者您可以在应用程序服务器级别进行设置.Gunicorn具有 超时 设置.

Or you could set it at the application server level. Gunicorn has a timeout setting.

这篇关于如何为Django Rest HTTP请求设置超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 15:37
查看更多