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