Flask documents used to describe how to do this, but have been deleted due to performance notes below. You do not need Tornado to service your Flask application unless all of your asynchronous code is already written in Tornado.
Tornado's WSGI docs also describe this. They also contain a big warning that this is probably less efficient than using a dedicated WSGI application server such as uWSGI, Gunicorn, or mod_wsgi.
WSGI is a synchronous interface, and the Tornados concurrency model is based on single-threaded asynchronous execution. This means that running a WSGI application with Tornados WSGIContainer less scalable than running the same application on a multi-threaded WSGI server, such as gunicorn or uwsgi . Use the WSGIContainer only when there are advantages to combining Tornado and WSGI in the same process that outweighs the reduced scalability.
For example, use Gunicorn instead:
gunicorn -w 4 app:app
After all this, if you really really want to use Tornado, you can use the template described in the docs:
from tornado.wsgi import WSGIContainer from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop from yourapplication import app http_server = HTTPServer(WSGIContainer(app)) http_server.listen(5000) IOLoop.instance().start()
davidism Jun 01 '15 at 0:10 2015-06-01 00:10
source share