一起使用烧瓶和龙卷风? [英] using Flask and Tornado together?

查看:143
本文介绍了一起使用烧瓶和龙卷风?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Flask 是我的忠实拥趸,部分原因是因为它很简单,部分原因是有很多 扩展程序。然而,Flask是为了在WSGI环境中使用而WSGI不是非阻塞的,所以(我相信)对于某些类型的应用程序来说,它不会像 Tornado 一样扩展。 / p>

因为每个人都有一个调用函数的URL调度器,两者都将使用Python文件(在Django中,您不会启动python文件,而是在烧瓶或龙卷风中执行)是否有两个独立的部分到您的网站是有意义的 - 一部分与Tornado运行非阻塞作业,另一部分用Flask写入?



如果这是一个好主意,你将如何去分享烧瓶和龙卷风之间的cookies /会话?我会遇到问题,因为Flask会使用自己的系统,Tornado会使用自己的系统吗?

50%的解决方案,饼干还没有测试,但现在我可以加载Flask应用程序使用龙卷风,并混合Tornado + Flask在一起:)

第一这里是 flasky.py 烧瓶应用程序所在的文件:

  from flask import Flask 
app = Flask(__ name__)

@ app.route('/ flask')
def hello_world():
return'这个来自Flask ^ _ ^'

,然后是 cyclone.py 文件,它将加载烧瓶应用程序和龙卷风服务器+一个简单的龙卷风应用程序,希望没有模块称为旋风^ _ ^

  from tornado.wsgi import WSGIContainer 
from tornado.ioloop从tornado.web导入IOLoop
导入FallbackHandler,RequestHandler,应用程序
from flasky import a

class MainHandler(RequestHandler):
def get(self):
self.write(This message from Tornado ^ _ ^)

$ tr = WSGIContainer(app)

application = Application([
(r/ tornado,MainHandler),
(r。*,FallbackHandler,dict ($ fallback = tr)),
))

if __name__ ==__main__:
application.listen(8000)
IOLoop.instance() )

希望这可以帮助那些想要混合它们的人:)

I am a big fan of Flask - in part because it is simple and in part because has a lot of extensions. However, Flask is meant to be used in a WSGI environment, and WSGI is not a non-blocking, so (I believe) it doesn't scale as well as Tornado for certain kinds of applications.

Since each one has an URL dispatcher which will call a function, and both will use Python files (in Django you dont launch the python file but in flask or tornado you do) do does it make sense to have two seperate parts to your website - one part running the non-blocking jobs with Tornado, and the other part written with Flask?

If this is a good idea, how would you go about sharing cookies / sessions between Flask and Tornado? Will I run into issues, since Flask will use it own system and Tornado will use its own system?

解决方案

i think i got 50% of the solution, the cookies are not tested yet, but now i can load Flask application using Tornado, and mixing Tornado + Flask together :)

first here is flasky.py the file where the flask application is:

from flask import Flask
app = Flask(__name__)

@app.route('/flask')
def hello_world():
  return 'This comes from Flask ^_^'

and then the cyclone.py the file which will load the flask application and the tornado server + a simple tornado application, hope there is no module called "cyclone" ^_^

from tornado.wsgi import WSGIContainer
from tornado.ioloop import IOLoop
from tornado.web import FallbackHandler, RequestHandler, Application
from flasky import app

class MainHandler(RequestHandler):
  def get(self):
    self.write("This message comes from Tornado ^_^")

tr = WSGIContainer(app)

application = Application([
(r"/tornado", MainHandler),
(r".*", FallbackHandler, dict(fallback=tr)),
])

if __name__ == "__main__":
  application.listen(8000)
  IOLoop.instance().start()

hope this will help someone that wants to mix them :)

这篇关于一起使用烧瓶和龙卷风?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆