I have a huge list of elements which somehow must be processed. I know that it can be done with Process from multiprocessing by:
pr1 = Process(calculation_function, (args, ))
pr1.start()
pr1.join()
and so I can create lets say 10 processes and pass arguments split by 10 to args. And then job is done.
But I do not want to create it manually and calculate it manually. Instead I want to use ProcessPoolExecutor and I am doing it like this:
executor = ProcessPoolExecutor(max_workers=10)
executor.map(calculation, (list_to_process,))
calculation is my function which do the job.
def calculation(list_to_process):
for element in list_to_process:
# .... doing the job
list_to_process is my list to be processed.
But instead after running this code, iteration on loop goes just one time. I thought that
executor = ProcessPoolExecutor(max_workers=10)
executor.map(calculation, (list_to_process,))
is the same as this 10 times:
pr1 = Process(calculation, (list_to_process, ))
pr1.start()
pr1.join()
But it seems to be wrong.
How to achieve real multiprocessing by ProcessPoolExecutor?