Created
October 14, 2013 02:54
-
-
Save yareally/6969975 to your computer and use it in GitHub Desktop.
Run tornado web server simultaneously with a Flask app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from tornado.web import RequestHandler, Application, FallbackHandler | |
from tornado.wsgi import WSGIContainer | |
from tornado.ioloop import IOLoop | |
from flask_main import app | |
class MainHandler(RequestHandler): | |
""" | |
Class for dealing with Tornado web stuff | |
""" | |
def get(self): | |
""" | |
Type http://<server-ip-here>:5000/tornado to access tornado stuff | |
@return: | |
""" | |
self.write("Tornado side message") | |
flask_app = WSGIContainer(app) | |
application = Application([ | |
# tornado http request, since the URL has /tornado | |
(r"/tornado", MainHandler), | |
# pass off to Flask if we're not using tornado | |
(r".*", FallbackHandler, | |
dict(fallback=flask_app)),], debug=True) | |
if __name__ == "__main__": | |
# Type http://<server-ip-here>:5000 to access flask stuff | |
application.listen(5000, '0.0.0.0') | |
IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment