我正在尝试使用 futures backport 包在 Python 中使用 ThreadPoolExecutor。然而,问题是所有线程都是同时执行的,因此没有发生实际的池化。更具体地说,我得到了该函数的 10 个线程,而不是 5 个线程,然后是其他线程。我使用下面的代码你发现有什么问题还是只是向后移植的实现?谢谢!
with ThreadPoolExecutor(max_workers=5) as executor:
futures = [executor.submit(f, X, y) for t in range(10)]
for future in as_completed(futures):
self.trees.append(future.result())