python 使用多线程导致内存泄漏问题

tech2026-02-09  1

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)

 

最新回复(0)