Is it possible to run Falcon app from Python?
Asked Answered
G

1

2

I'm moving my code from Flask to Falcon and a small annoyance is that I can't seem to find way to run my Falcon-based app from the __main__ method. In my Flask app I had this:

if __name__ == '__main__':
    app.run(port=os.getenv('PORT', 5000))

Is there a way to do the same for the Falcon app? I don't mind to use a wrapper like Gunicorn but that one also seems to not run (easily) from the __main__ as well

Note: This is strictly for development purposes, I know how to run the Falcon app in production

Gardie answered 19/3, 2019 at 23:54 Comment(0)
L
4

Sure use wsgiref, e.g.:

from wsgiref import simple_server

if __name__ == '__main__':
    with simple_server.make_server('', os.getenv('PORT', 5000), app) as httpd:
        httpd.serve_forever()
Lowndes answered 20/3, 2019 at 0:1 Comment(1)
Fantastic! This is exactly what I was looking for!Gardie

© 2022 - 2024 — McMap. All rights reserved.