首页 > 解决方案 > 如何将多个参数传递给 ThreadPoolExecutor executor.map()?

问题描述

那么问题是我有一个像这样的列表:[{'Title':'asdada', 'Seasons':[{'Number': 1, 'Id':'243sfs2'}, {'Number': 2, 'Id':'434sdfsdf'}]}]

包含如上所述的多个字典,问题是我需要使用所有 seasons['Id'] 对 API 执行多个请求(是的,它是一个刮板),所以我需要使用 ThreadPoolExecutor 因为列表很大. 发出请求并抓取所有数据的函数是:

def get_episodes(self, seasons): for season in seasons: season_id = season['Id'] url = f'https//asdads/{season_id} response = requests.get(url).json()

如您所见,该函数接收参数“seasons”,它是主要列表中每个元素的键“Seasons”。问题是我不知道如何使用每个迭代的这个键,就像执行器中的参数一样

with ThreadPoolExecutor(max_workers=3) as executor: executor.map(self.get_episodes('Season' values here), iterable_list)

是否有可能通过这个论点?

标签: pythonmultithreadingconcurrencyargumentsthreadpoolexecutor

解决方案


推荐阅读