Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Parallel processing of N files in list [closed]

Tags:

python

list

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

like image 993
user3292147 Avatar asked Oct 16 '25 15:10

user3292147


1 Answers

Try to use parallel map:

import multiprocessing
pool = multiprocessing.Pool()
pool.map(function_x, list_of_files)
like image 77
Dima Kudosh Avatar answered Oct 18 '25 12:10

Dima Kudosh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!