python自定义线程池

# coding=utf-8
import threading
import queue
class ThreadPoll:
    def __init__(self,maxsize):
        self.max=maxsize
        self.p=queue.Queue(self.max)
        for i in range(maxsize):
            self.p.put(threading.Thread)
    def get_thread(self):
        return  self.p.get()
    def add_thread(self):
        self.p.put(threading.Thread)
def call_bj(i,p):
    print(i)
    p.add_thread()
pool=ThreadPoll(5)
for i in range(100):
    obj=pool.get_thread()
    tar=obj(target=call_bj,args=(i,pool))
    tar.start()

你可能感兴趣的:(Java编程,测试经验总结)