How do I run a flask app in gunicorn if I used the application factory pattern?

Create a file under your project with the following contents, then point Gunicorn at it.

from my_project import create_app

app = create_app()
gunicorn -w 4 my_project.wsgi:app
# -w 4 specifies four worker processes

If you’re using the application factory pattern, Gunicorn allows specifying a function call like my_project:create_app(). For most cases, you can the skip making a file and tell Gunicorn how to create your app directly.

gunicorn -w 4 "my_project:create_app()"

Note that the quotes are necessary in some shells where parentheses have special meaning.

Leave a Comment