如何在python中使用threading.Semaphore和ThreadPoolExecutor
我想知道如何在如何在python中使用threading.Semaphore和ThreadPoolExecutor,python,multithreading,concurrency,threadpoolexecutor,concurrent.futures,Python,Multithreading,Concurrency,Threadpoolexecutor,Concurrent.futures,我想知道如何在ThreadPoolExecutor 我的代码是这样的 def download_one(url): requests.get(url) ... ... ... return 'ok' def download_all(urls): with ThreadPoolExecutor(max_workers=7) as executor: return executor.map(download_one, urls, t
ThreadPoolExecutor
我的代码是这样的
def download_one(url):
requests.get(url)
...
...
...
return 'ok'
def download_all(urls):
with ThreadPoolExecutor(max_workers=7) as executor:
return executor.map(download_one, urls, timeout=20)
download_all(["url-1", "url-2"])
我的代码以这种方式工作得非常好
但我的问题是,我可能会使用不同的URL多次调用download\u all
函数
我的程序有一个更新,这些更新是URL
,我想把它们转移到download\u all
功能
但是,当我第一次调用download\u all
函数时,我希望它能够工作
当我第二次叫它的时候,等它做完再重新开始
因此,在多次添加函数时,始终有7个worker
正在运行,并且没有添加到worker
以ThreadPoolExecutor(最大工作线程数=7)作为执行器: