lwzm
6/24/2014 - 8:15 AM

tornado_and_flask.py

# tornado:
import datetime
from tornado.web import Application, RequestHandler, asynchronous
from tornado.ioloop import IOLoop
from tornado.options import parse_command_line

io_loop = IOLoop.instance()
delay = datetime.timedelta(milliseconds=3)

class Sleep(RequestHandler):
    @asynchronous
    def get(self):
        io_loop.add_timeout(delay, lambda: self.finish("end"))

if __name__ == "__main__":
    parse_command_line()
    Application([(r"/", Sleep)]).listen(8000)
    io_loop.start()


# flask:
import sys
import time
from urllib.parse import unquote
from urllib.request import urlopen
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    f = urlopen('http://localhost:8000/')
    return f.read()

if __name__ == "__main__":
    app.run(host="0.0.0.0", threaded=True, debug=True)