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