python线程池库threadpool使用实例
来源:互联网 发布:感情 知乎 编辑:程序博客网 时间:2024/06/08 06:12
安装:
pip install threadpool
使用实例:
# -*- coding: utf-8 -*-import threadpooldef hello(a): return 'hello: %s' % adef world(a, b): return 'world: %s, %s' % (a, b)def foobar(a, b, c): return 'foobar: %s, %s, %s' % (a, b, c)def print_result(req, result): print('The result is %s %s' % (req.requestID, result))data1 = [1, 2, 3, 4, 5]lst1 = (6, 6)lst2 = (7, 7)lst3 = (8, 8)data2 = [(lst1, None), (lst2, None), (lst3, None)]dct1 = {'a': 8, 'b': 9, 'c': 10}dct2 = {'a': 11, 'b': 12, 'c': 13}data3 = [(None, dct1), (None, dct2)]pool = threadpool.ThreadPool(5)requests1 = threadpool.makeRequests(hello, data1, print_result)requests2 = threadpool.makeRequests(world, data2, print_result)requests3 = threadpool.makeRequests(foobar, data3, print_result)[pool.putRequest(req) for req in requests1][pool.putRequest(req) for req in requests2][pool.putRequest(req) for req in requests3]pool.wait()
输出结果:
The result is 39748664 hello: 1The result is 39748720 hello: 2The result is 39748776 hello: 3The result is 39748832 hello: 4The result is 39748888 hello: 5The result is 39748944 world: 6, 6The result is 39749000 world: 7, 7The result is 39749056 world: 8, 8The result is 39749112 foobar: 8, 9, 10The result is 39749168 foobar: 11, 12, 13
0 0
- python线程池库threadpool使用实例
- python threadpool 线程池使用
- boost::threadpool线程池使用实例
- python线程池(threadpool)模块使用
- python线程池(threadpool)模块使用
- python线程池(threadpool)模块使用
- python 线程池threadpool(使用篇)
- python线程池(threadpool)模块使用
- Python 线程池(threadpool)
- python线程池(threadpool)模块使用python2.7
- ThreadPool 线程池的使用
- 线程池ThreadPool使用示例
- 线程池 ThreadPool 概念、应用实例
- threadpool——python线程池
- Python多线程简易版 - 线程池threadpool
- python 线程池threadpool之实现
- Python-线程池模块(threadpool.py)
- c# ThreadPool 线程池的使用
- rebase -i 编辑、删除的使用
- C++ Hook(钩子)编程,通过内联汇编,使类成员函数代替全局函数(静态函数)
- 实战——离散Hopfield神经网络的实现
- php 接口token生成验证
- C++内存分布与虚指针
- python线程池库threadpool使用实例
- Android 微信Tinker三分钟接入七分钟原理 让你成为热修复牛人
- java以某一编码方式读取CSV
- 机器学习实战笔记(二)
- golang程序版本管理
- buffer cache 深度解析
- 机器学习实战笔记
- 源码解读android 5.0控件TabLayout无法自定义下划线宽度问题
- 优先级队列---使用堆