import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import time
import os
from tornado import gen
from tornado.concurrent import run_on_executor
from concurrent.futures import ThreadPoolExecutor
from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)
class IndexHandler(tornado.web.RequestHandler):
executor = ThreadPoolExecutor(10)
@tornado.gen.coroutine
def get(self):
print "begin"
#time.sleep(10)
yield self.pin()
self.finish()
@run_on_executor
def pin(self):
os.system("ping -c 5 www.baidu.com")
print "ping_end"
if __name__ == "__main__":
tornado.options.parse_command_line()
app = tornado.web.Application(handlers=[(r"/sleep", IndexHandler)])
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()