'How to pass multiple arguments in Multiprocessing executor.map() function
I have been watching several videos on Multiprocessing map function.
I know that I can send one list as an argument to the function I want to target with Multiprocessing, and that will call the same function n times (dependent upon the size of that passed list).
What I am struggling to do is what if I want to pass multiple arguments to that function?
I basically have a List whose size is n (it can vary but for current case, its 209)
My function requires 3 arguments...
- the index of the list (0, 1, 2 etc.)
- Another list containing data
- A fixed integer value
I could have used the 2nd and 3rd arguments as global variables, but that doesn't work for me because I have to call the map function in a while loop... and in every another iteration, the values of these two will change.
My function returns two values which I need to access in the function from where it was called. This is what I have tried but it didn't work for me,
def main_fun():
with concurrent.futures.ProcessPoolExecutor() as executor:
results = executor.map(MyFun, (row, pop[0].data, fitness) for row in range(0, len(pop[0].data)))
for result in results:
print(result)
I also tried to use ZIP function but again, with no success.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
