Skip to content

Instantly share code, notes, and snippets.

@cesartalves
Forked from ianschenck/new_app.py
Created October 8, 2019 18:06
Show Gist options
  • Save cesartalves/4cd79f49aecf3e014cc529f33d8270a1 to your computer and use it in GitHub Desktop.
Save cesartalves/4cd79f49aecf3e014cc529f33d8270a1 to your computer and use it in GitHub Desktop.
Run your flask app under twisted wsgi, ALWAYS.
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()
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment