python线程池
来源:互联网 发布:豪沃克幕墙计算软件 编辑:程序博客网 时间:2024/05/27 12:22
import time# threadpool为线程池模块import threadpooldef test(str): print str time.sleep(2)if __name__ == "__main__": startTime = time.time() # 创建线程池,最多创建的线程数为10 pool = threadpool.ThreadPool(10) # 创建请求(类似于线程创建),test是目标函数,arts_list为目标函数的参数 requests = threadpool.makeRequests(test, args_list=['thread1', 'thread2', 'thread3', 'thread4']) # 将请求放入线程池中启动 [pool.putRequest(req) for req in requests] # 等待所有线程执行完毕 pool.wait() endTime = time.time() print endTime - startTime
单线程执行该方法的结果
def test(str): print str time.sleep(2)if __name__ == "__main__": startTime = time.time() for i in range(4): test(str(i)) endTime = time.time() print endTime - startTime
阅读全文
0 0
- Python 线程池
- python 线程池
- Python实现线程池
- python实现线程池
- python线程池实现
- python 的线程池
- Python线程池
- Python实现线程池
- python线程池实例
- Python线程池实现
- python线程池
- python线程池设计
- Python实现线程池
- Python线程池(threading)
- 线程池python实现
- python 线程池实现
- python线程池
- python 线程池创建
- OSG-交互
- 归并排序递归实现
- Leetcode#20. Valid Parentheses(有效括号-栈)
- 学习笔记(逆向汇编)Day1-Day5
- react-native中TouchableXXX事件的分发
- python线程池
- 2018搜狐编程题-贪心算法-二维装箱问题
- Android Multidex原理及实现
- 迭代器(iterator)模式
- Git常用的命令
- 智能指针句柄类
- 平衡二叉树的旋转
- PHP程序员进阶学习书籍参考指南
- ZOJ