问题描述
我想运行一个简单的应用程序在与龙卷风烧瓶。我该怎么做呢?我想用Python 2.7和最新的Tornado版本(4.2)。 from flask import Flask
app = Flask(__ name__)
@ app.route('/')
def hello():
return'Hello World!'
if __name__ =='__main__':
app.run()
WSGIContainer
下运行一个WSGI应用程序比在多线程WSGI服务器(如<$ c $)中运行相同应用程序的可扩展性要低c> gunicorn 或 uwsgi
。使用 WSGIContainer
只有当在同一个进程中将Tornado和WSGI合并在一起的好处超过减少的可伸缩性时才可以使用 例如,使用Gunicorn代替:
gunicorn -w 4 app:app
毕竟,如果真的,真的还是要用Tornado ,您可以使用文档中描述的模式:tornado.wsgi中的
从tornado导入WSGIContainer
.httpserver import HTTPServer
from tornado.ioloop从yourapplication import app导入IOLoop
$ b http_server = HTTPServer(WSGIContainer(app))
http_server.listen(5000)
IOLoop.instance()。start()
I would like to run a simple app written in Flask with Tornado. How do I do this? I want to use Python 2.7 and the latest Tornado version (4.2).
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World!'
if __name__ == '__main__':
app.run()
The Flask docs used to describe how to do this, but it has been removed due to the performance notes below. You don't need Tornado to serve your Flask app, unless all your async code is already written in Tornado.
The Tornado docs about WSGI describe this as well. They also include a big warning that this is probably less performant than using a dedicated WSGI app server such as uWSGI, Gunicorn, or mod_wsgi.
For example, use Gunicorn instead:
gunicorn -w 4 app:app
After all that, if you really, really still want to use Tornado, you can use the pattern 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()
这篇关于如何运行与龙卷风Flask应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!