gpt4 book ai didi

python - ProcessPoolExecutor 传递多个参数

转载 作者:行者123 更新时间:2023-12-04 00:23:04 25 4
gpt4 key购买 nike

ESPNP 播放器免费

class ESPNPlayerFree:

def __init__(self, player_id, match_id, match_id_team):
...

团队列表1:
 [('277906', 'cA2i150s81HI3qbq1fzi', 'za1Oq5CGHj3pkkXWNghG'), ('213674', 'cA2i150s81HI3qbq1fzi', 'za1Oq5CGHj3pkkXWNghG')]

代码
 with concurrent.futures.ProcessPoolExecutor(max_workers=30) as executor:
results = list(executor.map(ESPNPlayerFree, teamList1))

类型错误: __init__() missing 2 required positional arguments: 'match_id' and 'match_id_team'

最佳答案

编辑:

使用多处理池,您将使用 starmap()它将使用 start *将元组解包为参数

ESPNPlayerFree( *('277906', 'cA2i150s81HI3qbq1fzi', 'za1Oq5CGHj3pkkXWNghG') ) 
ESPNPlayerFree( *('213674', 'cA2i150s81HI3qbq1fzi', 'za1Oq5CGHj3pkkXWNghG') )

好像 concurrent.futures.ProcessPoolExecutor没有 starmap()所以它将它作为一个参数发送 - tuple
ESPNPlayerFree( ('277906', 'cA2i150s81HI3qbq1fzi', 'za1Oq5CGHj3pkkXWNghG') ) 
ESPNPlayerFree( ('213674', 'cA2i150s81HI3qbq1fzi', 'za1Oq5CGHj3pkkXWNghG') )

你需要在函数内部解压它
def __init__(self, data):
player_id, match_id, match_id_team = data

关于python - ProcessPoolExecutor 传递多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59095085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com