Why would I want to combine Flask with the Tornado Server rather than using Tornado whole framework?
-
-
Answer:
My current project requires real-time stuff so I started to develop it using Tornado and then decided to switch to the Quora model -- use a traditional Web framework for most things, and connect back to Tornado for the real-time stuff. Quora uses Pylons, but Pylons reached its end-of-life with 1.0, and it's now Pyramid, which is really repoze.bfd and shares no code with Pylons 1.0. So I swapped out Pylons for Flask and use http://Socket.IO (http://socket.io/) to connect back to Torando for real-time connections. In addition to just being really-well designed, Flask has an amazing debugger that makes me more productive, and it's easier to write unittests for Flask because you can write them in a traditional way and don't have to contend with Tornado's IOLoop. When I switched to this model, the development process sped up considerably. For real-time stuff, you could forgo Tornado all together and instead use gevent to deploy your Flask app (http://flask.pocoo.org/docs/deploying/others/#gevent), like some have done with Django and Pyramid (http://flask.pocoo.org/docs/deploying/others/#gevent), but I haven't tried this yet.
James Thornton at Quora Visit the source
Other answers
You wouldn't want to do this normally. Tornado pretty much offers you everything that Flask does for blocking type web applications. On the other hand, combining Django with Tornado makes much more sense... Unlike Flask and Tornado, Django is a vast and comprehensive framework, that has a lot of sub components under its umbrella so there are reasonable use cases where you would want to leverage these. You could use Django, for example, as your REST API server and have Tornado compliment it as a websocket, comet or HTTP events based pub/sub server for sending your clients notifications and alerts ... Django and Flask would be poor choices for this feature. Even in this scenario, I don't personally think its good design to integrate the two at the wsgi level, rather you should build them as independent servers that communicate from separate processes.
Shidan Gouran
Depend on the throughput of your realtime components, you may need Tornado or you could rely on something easier to program like Gevent. Here is a comparison http://blog.kgriffs.com/2012/12/12/gevent-vs-tornado-benchmarks.html Generally Flask is much easier to use than Tornado. And if you want to use Flask on Tornado (as an hosted WSGI application), beware that any library called from your Flask app may block the whole Tornado worker process. Gevent could patch some of the pure Python libraries to work co-opertaively.
Ryan Gao
Not sure how you want to combine it. If you want to use Tornado as WSGI server, it will work just fine. If you want to build asynchronous server, probably it won't work. Flask is built on top of the Werkzeug, which is basically collection of the WSGI utilities and WSGI synchronous in its nature.
Serge Koval
You should read all the comments in Tornado's http://wsgi.py (https://github.com/facebook/tornado/blob/master/tornado/wsgi.py) especially WSGIContainer ("It has not yet been thoroughly tested in production") and ofcourse it won't support async with external frameworks
Suman Raj
Related Q & A:
- I want to avoid dynamic pivot in SQL Server.Best solution by Stack Overflow
- Why does yahoo keep asking me if I want to leave my ID signed in for 2 weeks?Best solution by Yahoo! Answers
- Why am I not able to send SMS using Yahoo Messenger?Best solution by Yahoo! Answers
- Why can I download attachments using Yahoo Classic Mail, but not using newer Yahoo Mail?Best solution by Yahoo! Answers
- Why cannot I print a whole page?Best solution by smallbusiness.chron.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.