ESPNPlayerFree
class ESPNPlayerFree:
def __init__(self, player_id, match_id, match_id_team):
...
teamList1:
[('277906', 'cA2i150s81HI3qbq1fzi', 'za1Oq5CGHj3pkkXWNghG'), ('213674', 'cA2i150s81HI3qbq1fzi', 'za1Oq5CGHj3pkkXWNghG')]
Code
with concurrent.futures.ProcessPoolExecutor(max_workers=30) as executor:
results = list(executor.map(ESPNPlayerFree, teamList1))
TypeError: __init__() missing 2 required positional arguments: 'match_id' and 'match_id_team'
Since starmap
is not available, create a helper factory function for this:
def player_helper(args):
return ESPNPlayerFree(*args)
with concurrent.futures.ProcessPoolExecutor(max_workers=30) as executor:
results = list(executor.map(player_helper, teamList1))
Or make it into a classmethod
for class ESPNPlayerFree
if it makes more sense:
class ESPNPlayerFree:
...
@classmethod
def expand_args(cls, args):
return cls(*args)
with concurrent.futures.ProcessPoolExecutor(max_workers=30) as executor:
results = list(executor.map(ESPNPlayerFree.expand_args, teamList1))
EDIT:
With multiprocessing Pool you would use starmap() and it would use start *
to unpack tuple to arguments
ESPNPlayerFree( *('277906', 'cA2i150s81HI3qbq1fzi', 'za1Oq5CGHj3pkkXWNghG') )
ESPNPlayerFree( *('213674', 'cA2i150s81HI3qbq1fzi', 'za1Oq5CGHj3pkkXWNghG') )
It seems concurrent.futures.ProcessPoolExecutor
doesn't have starmap()
so it sends it as one argument - tuple
ESPNPlayerFree( ('277906', 'cA2i150s81HI3qbq1fzi', 'za1Oq5CGHj3pkkXWNghG') )
ESPNPlayerFree( ('213674', 'cA2i150s81HI3qbq1fzi', 'za1Oq5CGHj3pkkXWNghG') )
and you would need to unpack it inside function
def __init__(self, data):
player_id, match_id, match_id_team = data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With