Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/bin/env python
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.httpclient
import tornado.gen
from tornado.concurrent import run_on_executor
#if < python3.2 you need do `sudo pip install futures`
from concurrent.futures import ThreadPoolExecutor
import time
from tornado.options import define, options
define("port", default=7000, help="run on the given port", type=int)
class SleepHandler(tornado.web.RequestHandler):
executor = ThreadPoolExecutor(10)
def get(self):
start = time.time()
res = yield self.sleep()
self.write("when i sleep %f s" % (time.time() - start))
def sleep(self):
return 5
class JustNowHandler(tornado.web.RequestHandler):
def get(self):
self.write("i hope just now see you")
if __name__ == "__main__":
app = tornado.web.Application(handlers=[
(r"/sleep", SleepHandler), (r"/justnow", JustNowHandler)])
http_server = tornado.httpserver.HTTPServer(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment