1 #!/usr/bin/env python
2 import threadpool
3 import time
4 import random
5
6 def hello(self):
7 time.sleep(2);
8 return "hello";
9
10 def print_result(request, result):
11 print "the result is %s %r"%(request.requestID, result)
12
13 data = [ random.randint(1, 10) for i in range(20) ]
14
15 pool = threadpool.ThreadPool(5)
16 requests = threadpool.makeRequests(hello, data, print_result)
17 [pool.putRequest(req) for req in requests]
18 pool.wait()
19
输出结果:
the result is 140118496492576 'hello'
the result is 140118496492720 'hello'
the result is 140118496492864 'hello'
the result is 140118496493152 'hello'
the result is 140118496493008 'hello'
the result is 140118496493440 'hello'
the result is 140118496497744 'hello'
the result is 140118496493296 'hello'
the result is 140118496497888 'hello'
the result is 140118496498032 'hello'
the result is 140118496498176 'hello'
the result is 140118496498320 'hello'
the result is 140118496498464 'hello'
the result is 140118496498608 'hello'
the result is 140118496498752 'hello'
the result is 140118496498896 'hello'
the result is 140118496499040 'hello'
the result is 140118496499184 'hello'
the result is 140118496499472 'hello'
the result is 140118496499328 'hello'
相关推荐
【Python】python threadpool python多线程 Python语言基础 文件清单 └── threadpool-1.2.7 ├── CHANGELOG.txt ├── doc │ ├── api │ │ ├── class-tree.html │ │ ├── epydoc.css │ │...
python threadpool python多线程
主要介绍了python线程池(threadpool)模块使用笔记详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
可以使用python语言自己实现线程池,或者可以使用第三方包threadpool线程池包,本主题主要介绍threadpool的使用以及其里面的具体实现。 1、安装 使用安装: pip installthreadpool 2、使用 (1)引入threadpool...
主要为大家详细介绍了python线程池threadpool的实现,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
pythonthreadpool阅读版
pthread实现的threadpool
ThreadPool 线程池管理单元 带调用例子
使用现代的替代方法,例如标准库中的模块,甚至使用asyncio的异步方法。 描述 线程池是维护工作线程池以并行执行耗时的操作的对象。 它通过将作业放入工作请求队列中,将作业分配给线程,然后由下一个可用线程将其...
Linux C线程池实现,有代码和调用参考。线程池代码有详细注释,对于互斥锁使用情况有详细说明
主要介绍了浅谈python 线程池threadpool之实现,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
C#例子代码 A0320_ThreadPoolC#例子代码 A0320_ThreadPoolC#例子代码 A0320_ThreadPoolC#例子代码 A0320_ThreadPoolC#例子代码 A0320_ThreadPoolC#例子代码 A0320_ThreadPoolC#例子代码 A0320_ThreadPoolC#例子代码 ...
threadPool的实现代码
javascript ThreadPool
使用Boost库,Threadpool线程池的使用,包括优先级任务处理,普通任务处理!