How can I set a request timeout using Python Flask? I\'m trying to compare Flask to some other framework and need to configure the timeouts to be equivalent.
Thanks!
WSGI is the protocol, a facade separating your code from the actual web server which runs it.
In the flask, you only create the logic of the server. On run, your Flask application is served by the WSGI server. The most common is uWSGI ( & nGinx proxy to the secure border between the outer world and your server). But you can use whichever WSGI server suits you best without need to change your code (nichol.as/benchmark-of-python-web-servers)*.
Flask itself ships only with the Development WSGI flask server. It means the server uses a lot of features to help the developer debug their application. These features make the server very slow. So when you do a benchmark of your app on the Development WSGI flask server, results have no value for you.
On the other hand, specialized production-ready WSGI servers (including uWSGI) are well optimized, tested and production-proven. Most of the features are usually turned off by default and allow you to fine-tune these powerful beasts for your application.
Deployment tutorials:
Now when I explained the context, back to your original question. I would set requests timeout in your:
import requests
requests.get('https://api.myapp.com', timeout=3)
http
{
server
{
…
location /
{
…
proxy_read_timeout 120s;
…
}
}
}