首页 > 编程语言 > 详细

low版的线程池

时间:2017-01-14 17:30:31      阅读:282      评论:0      收藏:0      [点我收藏+]
import threading,queue,time

class MythredPool(object):
    def __init__(self,max_num=20):
        self.queue = queue.Queue(max_num)
        for i in range(max_num):
            self.queue.put(threading.Thread)

    def get_thread(self):
        return self.queue.get()

    def put_shread(self):
        return self.queue.put(threading.Thread)


def func(pool,arg):
    time.sleep(2)
    print(arg)
    pool.put_shread()

p = MythredPool(10)

for i in range(100):
    thread = p.get_thread()
    t = thread(target=func,args=(p,i))
    t.start()

  

low版的线程池

原文:http://www.cnblogs.com/cloniu/p/6285543.html

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