python多线程模块threadpool简单使用
2012-05-12 22:54
393 查看
python实现线程池通常使用threading或thread模块来编写,现在已经有了threadpool模块来实现线程池。
英文文档见:http://www.chrisarndt.de/projects/threadpool/
中文文档见:http://gashero.yeax.com/?p=44
现给出一个简易的使用threadpool模块来实现线程池的例子:
本文出自 “Get and Share” 博客,请务必保留此出处http://dgfpeak.blog.51cto.com/195468/861994
英文文档见:http://www.chrisarndt.de/projects/threadpool/
中文文档见:http://gashero.yeax.com/?p=44
现给出一个简易的使用threadpool模块来实现线程池的例子:
#!/usr/bin/env python import threadpool import time,random def hello(str): time.sleep(2) return str def print_result(request, result): print "the result is %s %r" % (request.requestID, result) data = [random.randint(1,10) for i in range(20)] pool = threadpool.ThreadPool(5) requests = threadpool.makeRequests(hello, data, print_result) [pool.putRequest(req) for req in requests] pool.wait()
本文出自 “Get and Share” 博客,请务必保留此出处http://dgfpeak.blog.51cto.com/195468/861994
相关文章推荐
- python多线程模块threadpool简单使用
- python GUI编程(Tkinter)简单使用
- python 简单的绘图工具turtle使用详解
- 学习简单的python----最简单的python +3(写入XML,使用UDP发送)
- Python学习——实现简单的交互raw_input的使用
- python yield(生成器)的简单使用
- Python爬虫实践(二):Urllib库的简单使用
- 简单使用python将图片转换为字符画
- 使用Python的Bottle框架写一个简单的服务接口的示例
- Python使用Redis实现作业调度系统(超简单)
- python 使用 talib 和 numpy 的简单例子
- python3.6 使用 pymysql 连接 Mysql 数据库及 简单的增删改查操作
- 使用python的flask新建一个简单的站点前做的注意事项
- python简单之isinstance,type使用
- python中sys.exit() os._exit() exit() quit()的简单使用
- 使用python进行简单的猜数字游戏(while循环)
- 使用Python实现简单购物车
- python简单的使用(二)
- python之virtualenv的简单使用
- Python爬虫之urllib简单使用