class BoundedThreadPoolExecutor(ThreadPoolExecutor):
def __init__(self, max_workers=None, thread_name_prefix=''):
super().__init__(max_workers, thread_name_prefix)
self._work_queue = queue.Queue(self._max_workers * 2) # 队列大小为最大线程数的两倍
def fun(i):
time.sleep(5)
print(i)
if __name__ == '__main__':
with BoundedThreadPoolExecutor(15,'')as executor:
for i in range(1000000000):
executor.submit(fun, i)