2021年4月25日星期日

Pass dictionary to ThreadPoolExecutor.map

I have a function that takes a dictionary as input. I am trying to batch a dictionary and send it to ThreadPoolExecutor.map. I previously did the same thing with a list using the code below:

def batch(iterable, n=1):      l = len(iterable)      for ndx in range(0, l, n):          yield iterable[ndx:min(ndx + n, l)]    with ThreadPoolExecutor(max_workers=5) as executor:      results = executor.map(myFunc, batch(myList, 32))  

However this won't work with a dictionary. I could probably figure out how to batch a dictionary, but I am not sure how to send it to executor.map since doing:

results = executor.map(myFunc, dictionary)  

will not work.

Any ideas on a good solution?

https://stackoverflow.com/questions/67259668/pass-dictionary-to-threadpoolexecutor-map April 26, 2021 at 09:05AM

没有评论:

发表评论