Last active
July 30, 2023 03:00
-
-
Save ianschenck/977379a91154fe264897 to your computer and use it in GitHub Desktop.
Run your flask app under twisted wsgi, ALWAYS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == "__main__": | |
reactor_args = {} | |
def run_twisted_wsgi(): | |
from twisted.internet import reactor | |
from twisted.web.server import Site | |
from twisted.web.wsgi import WSGIResource | |
resource = WSGIResource(reactor, reactor.getThreadPool(), app) | |
site = Site(resource) | |
reactor.listenTCP(5000, site) | |
reactor.run(**reactor_args) | |
if app.debug: | |
# Disable twisted signal handlers in development only. | |
reactor_args['installSignalHandlers'] = 0 | |
# Turn on auto reload. | |
import werkzeug.serving | |
run_twisted_wsgi = werkzeug.serving.run_with_reloader(run_twisted_wsgi) | |
run_twisted_wsgi() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == "__main__": | |
app.run() |
Thanks for the code. How to run this app with the debug flag?
Just activate it via env:
FLASK_DEBUG=1
Thanks for the script. Can you explain what's going? Also how do you control a WSGI app running on Twisted Web?
real Big Thanks from the heart
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the code. How to run this app with the debug flag?