首页 > 编程语言 > 详细

多线程池

时间:2017-03-04 21:09:35      阅读:207      评论:0      收藏:0      [点我收藏+]

一、low版

 1 #!/usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 import threading
 4 import queue
 5 import time
 6 class threadpool:
 7     def __init__(self,max_num=20):
 8         self.queue = queue.Queue(max_num)
 9         for i in range(max_num):
10             self.queue.put(threading.Thread)
11     def get_thread(self):
12         return self.queue.get()
13     def add_thread(self):
14         self.queue.put(threading.Thread)
15 
16 def fun(pool,a1):
17     time.sleep(1)
18     print(a1)
19     pool.add_thread()
20 p = threadpool()
21 for i in range(50):
22     ret = p.get_thread()
23     t= ret(target= fun,args=(p,i,))
24     t.start()

 

多线程池

原文:http://www.cnblogs.com/Erick-L/p/6502576.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!