low版的线程池

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()

  

原文地址:https://www.cnblogs.com/cloniu/p/6285543.html