Python中的uWSGI请求超时 [英] uWSGI request timeout in Python

查看:91
本文介绍了Python中的uWSGI请求超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在 uWSGI 中设置请求超时,我不确定设置是否正确.似乎有多个超时选项(套接字、接口等),并且不清楚要配置哪个设置或在哪里设置它.

Trying to set the timeout for requests in uWSGI, I'm not sure of the correct setting. There seem to be multiple timeout options (socket, interface, etc.) and it's not readily evident which setting to configure or where to set it.

我正在寻找的行为是延长对 REST 应用程序资源层的请求的时间.

The behavior I'm looking for is to extend the time a request to the resource layer of a REST application can take.

推荐答案

您可能正在寻找 harakiri 参数 - 如果请求花费的时间超过指定的 harakiri 时间(以秒为单位),请求将被丢弃并回收相应的工人.

You're propably looking for the harakiri parameter - if request takes longer than specified harakiri time (in seconds), the request will be dropped and the corresponding worker recycled.

对于独立的 uwsgi(ini 配置):

For standalone uwsgi (ini config):

[uwsgi]
http = 0.0.0.0:80
harakiri = 30
...

如果你在 uwsgi 之前有 nginx 代理,你也必须增加超时时间:

If you have nginx proxy before uwsgi you have to increase timeout as well:

  location / {
    proxy_pass http://my_uwsgi_upstream;
    proxy_read_timeout 30s;
    proxy_send_timeout 30s;
  }

如果您(出于某种奇怪的原因)希望超时时间高于 60 秒,您可以考虑通过 uwsgi 协议进行通信.配置和nginx站点很相似:

If you want (for some strange reason) higher timeout than 60s, you might consider communication over uwsgi protocol. Configuration is quite similar nginx site:

location / {
    uwsgi_read_timeout 120s;
    uwsgi_send_timeout 120s;
    uwsgi_pass  my_upstream;
    include     uwsgi_params;
}

uwsgi:

[uwsgi]
socket = 0.0.0.0:80
protocol = uwsgi
harakiri = 120
...

这篇关于Python中的uWSGI请求超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆