python中concurrent.ThreadPoolExecutor存在问题

python中concurrent.ThreadPoolExecutor存在问题,python,multithreading,Python,Multithreading,我做了一个函数,给了一个列表,上面有不同图片的链接,他们会下载它们。为了加快这个过程,我使用了线程。这是我写的: 以ThreadPoolExecutor()作为执行器的: executor.map(self.\u descargar\u imagen\u,self.links\u paginas) 这里的\uuuuu descargar\u imagen\uuuuuuu是一个下载图像和链接的函数。paginas是包含所有链接的列表。问题在于,出于某种原因,使用该代码,程序不会等待所有线程完成,

我做了一个函数,给了一个列表,上面有不同图片的链接,他们会下载它们。为了加快这个过程,我使用了线程。这是我写的:

以ThreadPoolExecutor()作为执行器的
:
executor.map(self.\u descargar\u imagen\u,self.links\u paginas)

这里的
\uuuuu descargar\u imagen\uuuuuuu
是一个下载图像和链接的函数。paginas是包含所有链接的列表。问题在于,出于某种原因,使用该代码,程序不会等待所有线程完成,因此它只下载部分图像。有没有办法让程序等待所有线程使用concurrent.futures ThreadPoolExecutor终止?

使用multiprocessing.pool:

from multiprocessing.pool import ThreadPool
checker = ThreadPool(processes).imap_unordered(downloader_function, url_list)
for foo in checker:
    print(foo)
其中,“processs”是您希望运行的进程数。 您可以在os/multiprocessing中使用cpu_count()函数来获得给定系统上可以运行的最大进程数