How do I run twisted with flask? How do I run twisted with flask? flask flask

How do I run twisted with flask?


My personal opinion: running Flask in Twisted's reactor isn't a good idea because Twisted's reactor is blocked when a request is processed by Flask.

I think you might be interested in Klein, which provided API similar to Flask, but works on Twisted out of the box: http://klein.readthedocs.io/en/latest/

Another option: I'd take a look into nginx as a reverse proxy for Flask applications instead of Twisted. nginx runs in a separate process and isn't blocked while a request is processed by Flask.https://www.nginx.com/resources/admin-guide/reverse-proxy/


You can use twisted web, as documented on the Flask deploy documentation. Here's how I managed to run a server on my machine:

pip3 install twisted[tls]export PYTHONPATH=${PYTHONPATH}:${PWD} # exports python pathtwistd  web -n --port tcp:5000 --wsgi path-to-your-app-root --logfile log.txt

Though I've had some issues with the server after it's up and running for my particular scenario, this might work for you