Gunicorn Workers and Threads

Let me attempt an answer. Let us assume that at the beginning my deployment only has a single gunicorn worker. This allows me to handle only one request at a time. My worker’s work is just to make a call to google.com and get the search results for a query. Now I want to increase … Read more

110: Connection timed out (Nginx/Gunicorn)

You could try upgrading the timeout for your proxy pass in Nginx by adding: proxy_connect_timeout 75s; proxy_read_timeout 300s; on /var/nginx/sites-available/[site-config] or /var/nginx/nginx.conf if you want to increase the timeout limite on all sites served by nginx. You must add –timeout 300 as well to your gunicorn process/config. This solved my problems in the past with … Read more

Host Django on subfolder

My comment doesn’t show the whole picture. When I’ve run Django sites on subfolders, I like to use a dynamic config so that you can still access the machine directly (without the proxy) and have a working web-app. This can help a LOT for debugging tricky stuff like this that is hard to reproduce in … Read more

How to use Flask-Script and Gunicorn

As Dhaivat said, you can just use your Flask app directly with Gunicorn. If you still want to use Flask-Script, you will need to create a custom Command. I don’t have any experience with Gunicorn, but I found a similar solution for Flask-Actions and ported it to Flask-Script, although be warned, it’s untested. from flask_script … Read more

How do I get my FastAPI application’s console log in JSON format with a different structure and different fields?

You could do that by creating a custom Formatter using the built-in logger module. You can use the extra parameter when logging messages to pass contextual information, such as url and headers. Python’s JSON module already implements pretty-printing JSON data in the dump() function, using the indent parameter that allows you to define the indent … Read more

How to run Flask with Gunicorn in multithreaded mode

You can start your app with multiple workers or async workers with Gunicorn. Flask server.py from flask import Flask app = Flask(__name__) @app.route(“https://stackoverflow.com/”) def hello(): return “Hello World!” if __name__ == “__main__”: app.run() Gunicorn with gevent async worker gunicorn server:app -k gevent –worker-connections 1000 Gunicorn 1 worker 12 threads: gunicorn server:app -w 1 –threads 12 … Read more