uWSGI request timeout in Python

PythonUwsgi

Python Problem Overview


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.

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

Python Solutions


Solution 1 - Python

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.

For standalone uwsgi (ini config):

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

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;
  }

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
...

Solution 2 - Python

Setting http-timeout worked for me. I have http = :8080, so I assume if you use file system socket, you have to use socket-timeout.

Solution 3 - Python

it worked for me by comment #master = true and put this, lazy-apps = true

in uwsgi.ini file

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJuan Carlos CotoView Question on Stackoverflow
Solution 1 - PythonTombartView Answer on Stackoverflow
Solution 2 - PythoniuriiView Answer on Stackoverflow
Solution 3 - PythonShahramView Answer on Stackoverflow