import os
import sys
import time import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.gen
from tornado.concurrent import run_on_executor
from concurrent.futures import ThreadPoolExecutor
from tornado.options import define, options class HasBlockTaskHandler(tornado.web.RequestHandler):
executor = ThreadPoolExecutor(20) #起线程池,由当前RequestHandler持有 @tornado.gen.coroutine
def get(self):
strTime = time.strftime("%Y-%m-%d %H:%M:%S")
print "in get before block_task %s" % strTime
result = yield self.block_task(strTime)
print "in get after block_task"
self.write("%s" % (result)) @run_on_executor
def block_task(self, strTime):
print "in block_task %s" % strTime
for i in range(1, 16):
time.sleep(1)
print "step %d : %s" % (i, strTime)
return "Finish %s" % strTime if __name__ == "__main__":
tornado.options.parse_command_line()
app = tornado.web.Application(handlers=[(r"/sleep", HasBlockTaskHandler)], autoreload=False, debug=False)
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(8888)
tornado.ioloop.IOLoop.instance().start()

最新文章

  1. linux ps命令,查看进程cpu和内存占用率排序(转)
  2. CSS的margin塌陷(collapse)
  3. php每天一题:strlen()与mb_strlen()的作用分别是什么
  4. MSYS2的源配置
  5. less和sass的介绍和差异
  6. [Linux监控]磁盘空间大小
  7. 线程池大小 & cpu core
  8. 解决Windows和Ubuntu时间不一致的问题
  9. Spring(3.2.3) - Beans(2): 属性注入 & 构造注入
  10. ashx+html+ajax
  11. perl 回调函数
  12. windows 7 忘記密碼,用“带命令行的安全模式”
  13. 使用Android Studio导入第三方库项目
  14. codevs 1069 关押罪犯
  15. Git常用命令使用大全
  16. Python tkinter 学习记录(一) --label 与 button
  17. wordpress背景添加跟随鼠标动态线条特效
  18. 大数据python词频统计之hdfs分发-cacheArchive
  19. Java学习路线教程之JDBC基本操作
  20. 【云迁移论文笔记】Cloud Migration Research:A Systematic Review

热门文章

  1. go chapter 6 - map array
  2. TYVJ2002 扑克牌
  3. 洛谷——P1862 输油管道问题
  4. Sqli-labs less 4
  5. UTF-8字符「EF BF BD」-备胎
  6. Java 线程池的实现
  7. 破解 apk
  8. [Codeforces #188] Tutorial
  9. Codeforces Round #449 (Div. 2)ABCD
  10. 【并查集】Gym - 101128B - Black Vienna