'Run flask application with uWSGI [duplicate]

I have a flask application and I would like to run it in a "production" way using uwsgi.

I have my launcher.py:

from app import app
import db

if __name__ == "__main__":
    db.init()
    app.run()

If I run the application with simply python launcher.py it's all ok. Especially, the db.init() is called correctly.

However, if I run using uwgsi with uwsgi app.ini , db.init() is not called.

Here is app.ini:

[uwsgi]
wsgi-file = launcher.py
callable = app
socket = :8080

I'm new with flask and uwsgi so probably I missed something but I could not find the solution in the different tutorials I read.

Also, in case you need it to understand the project, here is app.py:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return "hello from flask"

if __name__ == "__main__":
    db.init()
    app.run()

All files are in the same level in my project:

webserver/
    - app.ini
    - launcher.py
    - app.py
    - db.py

So, what am I doing wrong here?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source