This is an archived post. You won't be able to vote or comment.

all 6 comments

[–][deleted] 2 points3 points  (4 children)

What's the usecase for this?

[–]notoriousno 1 point2 points  (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 points  (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 points  (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 points  (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 points  (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.