There is list of files which I am processing one by one with some function:
list_of_files = [file_1, file_2, file_3, .... file_n]
# each file we are processing in function function_x(file)
for file in list_of_files:
function_x(file)
But it takes too long to process one file so I would like to process 4 files in paralel, when any of them is finished, to continue with next form list_of_files
Try to use parallel map:
import multiprocessing
pool = multiprocessing.Pool()
pool.map(function_x, list_of_files)
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