Skip to content Skip to sidebar Skip to footer

Processpoolexecutor Pass Multiple Arguments

ESPNPlayerFree class ESPNPlayerFree: def __init__(self, player_id, match_id, match_id_team): ... teamList1: [('277906', 'cA2i150s81HI3qbq1fzi', 'za1Oq5CGHj3pkkXWNghG'), ('213674

Solution 1:

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

Solution 2:

Since starmap is not available, create a helper factory function for this:

defplayer_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:

classESPNPlayerFree:

...

@classmethoddefexpand_args(cls, args):
    return cls(*args)


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

Post a Comment for "Processpoolexecutor Pass Multiple Arguments"