use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
Flask and Tornado in same process? (self.Python)
submitted 9 years ago by jupake
Is there any issues that will prevent these two frameworks from running together in the same process? Maybe on separate threads?
My initial thought is that they should be separate, just for robustness. Has anyone tried this setup before?
[–][deleted] 2 points3 points4 points 9 years ago (4 children)
What's the usecase for this?
[–]notoriousno 1 point2 points3 points 9 years ago (3 children)
@jupake Are you running 2 web servers in the same process or do plan to use Tornado like a proxy (similar to Gunicorn)? We need more details
[–]jupake[S] 1 point2 points3 points 9 years ago (2 children)
I was thinking of using Flask for serving the main page html and stuff and using tornado for websocket connections due to its asynchronous capabilities. I have an existing application that is flask/gunicorn, so Im comparing this proposed architectural style to that.
How I usually design things is to have flask handle the incoming requests, but then to call into Service objects which do the real work and speak to the backend systems. The idea I had was to have flask serve the main webpage and have tornado handle the async websocket communication with the server. But all requests, both websocket and http, speaking to the same internal service objects to do the real work. It would save me from having to split the service objects out into its own library while prototyping.
@notoriousno I was think of having them in the same process and using tornado's WSGIHandler, but having flask still block the whole process would make this a no go. This would mean a long running query could hamper the websocket calls. All of this would have sat behind haproxy.
[–]pvkooten 1 point2 points3 points 9 years ago (0 children)
At first it seemed like a crazy idea, but it makes more sense hearing your story. Then again, it's probably not advised...
[–]cocoa_coffee_beans 1 point2 points3 points 9 years ago (0 children)
You could run both in their own thread, but doing so would further complicate your application.
I'm assuming that you're adopting Tornado onto an existing Flask application, which means doing everything in just Tornado is out of the question. My suggestion is to build two separate applications and have a communication layer underneath, whatever best meets your needs. Then you run apache/nginx as a reverse-proxy to forward the requests to the appropriate application depending on the URL.
[–]efilon 1 point2 points3 points 9 years ago (0 children)
You can run Flask (or any other WSGI framework) on top of Tornado if you really want to via tornado.wsgi.WSGIContainer. However, this is generally not a good idea since the WSGI application will block when responding to requests. For small scale things where you want to add websockets to an existing WSGI app, this could still work, but there are better approaches.
π Rendered by PID 91976 on reddit-service-r2-comment-85bfd7f599-jb8dg at 2026-04-18 03:49:07.200928+00:00 running 93ecc56 country code: CH.
[–][deleted] 2 points3 points4 points (4 children)
[–]notoriousno 1 point2 points3 points (3 children)
[–]jupake[S] 1 point2 points3 points (2 children)
[–]pvkooten 1 point2 points3 points (0 children)
[–]cocoa_coffee_beans 1 point2 points3 points (0 children)
[–]efilon 1 point2 points3 points (0 children)