Waitress doesn't show anything when starting WSGI application

Question:

I want to run a flask app on waitress and it’s not working.
My code:

from flask import Flask

app = Flask(__name__)

if __name__ == "__main__":
    from waitress import serve
    serve(app)

When I try to run the app from cmd it gets stuck and doesn’t do anything.

Thanks

Asked By: RainbowSheep

||

Answers:

Why do you think it’s stuck? By default waitress has log level set to WARNING, so you don’t see any debug outputs.
Try changing logging configuration, like this:

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(message)s')

Answered By: Goofy_Goof

Try running "waitress-serve". I had the same issue.
For example, "waitress-serve –port=80 webproject.wsgi:application" worked for me.

Answered By: ThomasDKim

So here’s the full snippet

from flask import Flask
from waitress import serve
import logging

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(message)s')

app = Flask(__name__)


if __name__ == "__main__":
    serve(app)

running python3 main.py and stdout looks like this:

2022-10-03 14:53:14,410 Serving on http://0.0.0.0:8080

So, it was not stuck, just the logs were disabled

Answered By: Goofy_Goof
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.