Is there a function similar to pools.starmap that can be used with list of dictionaries?
Instead of :
pools.starmap(func, iterable_of_tuple)
You would have:
pools.starmapdict(func, iterable_of_dictionaries)
so that the function starmapdict would be responsible for unpacking the dictionary of argument of the function.
The workaround I used is:
from multiprocessing import Pool
data = [{"name": "Delphi", "age": 13}, {"name": "Orion", "age":24}, {"name": "Asher"}, {"name": "Baccus"}]
def fun_wrapper(dict_args):
return fun(**dict_args)
def fun(name="Iseult", age=30):
print(name, age)
if __name__ == '__main__':
with Pool(3) as pool:
pool.map(fun_wrapper, data)
The fun_wrapper function is responsible for unpacking the dictionary and giving it to the fun function.
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