本文介绍了如何运行与龙卷风Flask应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个简单的应用程序在与龙卷风烧瓶。我该怎么做呢?我想用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()


解决方案Flask文档用于描述如何执行此操作,但由于下面的性能说明,它已被删除。除非所有异步代码已经写入Tornado,否则您不需要使用Tornado来为您的Flask应用程序提供服务。 也描述了这一点。他们还包括一个大警告,这可能比使用专用的WSGI应用程序服务器(如uWSGI,Gunicorn或mod_wsgi)的性能要低。 WSGI是一个同步接口,而Tornado的并发模型是基于单线程异步执行的。这意味着在Tornado的 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应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:26