How to use the multiprocessing module to parallelize image processing?

There is a folder with n symbols and a server dual-processor, trying to raspredelit the function of image processing 2 process. Use the module multiprocessing. What they do: create an image list , declare a process using Pool(), declare a cycle depends on the length of the image list. The code now looks like:

img_list = [] #a List of images
 jobs_list = []#List of processes
 for _,_,file_names in os.walk(f_img):#
 for i in file_names:
 img_list.append(os.path.join(f_img, i))
 print("CUrrent list img: ", img_list)#Fill the list with images from a folder
 curent_img_list = deque(img_list)#For future use f-AI popleft()
 proc = Pool()
 while len(curent_img_list): #While not end of picture
 print("--------->>>> First While")
 for i in range(2):#"This I limit the number of processes
 job = proc.map(run, curent_img_list[0])#Start the process by passing the image to run
 curent_img_list.popleft()#Remove img from that list
 jobs_list.append(job)#Add the process in the list of running processes
 print("______>>>>>Iteration: ", i)


 while len(jobs_list):#While there are running processes, monitor their status
 print("--------->>>> Second While")
 for j in jobs_list:
j.join(timeout=0)
 if j.is_alive():
pass
else:
j.close()
 del(jobs_list[])# Here it is necessary to remove the process from the list, yet does not reach the stack

In progress error appears
job.join()
AttributeError: 'list' object has no attribute 'join'

Reprinted jobs_list, and there is a list of None.
Need help, I have something in Satake(
March 20th 20 at 11:44
1 answer
March 20th 20 at 11:46
Somehow everything complicated. Below given a guide.
The map method - he will spread the processes.
p.s. write without check

import multiprocessing as mp

def cube(x):
 return x**3

pool = mp.Pool(processes=4)
results = pool.map(cube, range(1,7))
print(results) #[1, 8, 27, 64, 125, 216]
Yeah, already figured out. Reinvent the wheel - Tianna.Sipes69 commented on March 20th 20 at 11:49

Find more questions by tags Python