Dec-05-2019, 07:03 PM
I am trying to improve the speed some of my code with Multiprocessing. Here is my code:
I am running this in terminal not IDLE.
What is the problem?
def create_averaging_process(processes, image_file): p = Process(target=get_averages, args=(image_file,)) processes.append(p) p.start() p.join() def make_threads(): processes = [] index = 0 allfiles = glob.glob(path+"/images/*") while (len(processes)<len(allfiles)): if (len(processes) - len([p for p in processes if not p.is_alive()]) < MAX_PROCESSES): create_averaging_process(processes, allfiles[index]) index+=1 print("done") def get_averages(image): with open(".img_averages.txt", 'a') as file: try: img = Image.open(image).convert('RGB') except Exception as e: print(e) print(img) img2 = img.resize((1, 1), Image.ANTIALIAS) #easiest way of getting average color - resize to 1x1 with anti-alias col = img2.getpixel((0, 0)) #get color of that single pixel try: something = col[2] #sometimes there are just singular ints print(col) file.write(str(col)) #writes color and size to file. Uses '#' \to separate them except Exception as e: print(e) make_threads()Everything runs fine - it even prints out the colour of the pixels. However, nothing is written to the file. No matter how many times I try, the file stays at 0 bytes.
I am running this in terminal not IDLE.
What is the problem?