I am developing an app that reads a video, converts it to images and then processes them in pairs. Since the app will be running on a Raspberry Pi, memory there's not much RAM available.
If i run the tasks in a simple for loop without the Executor memory behaves just fine but if i use the Executor scheduling 50 jobs, for example, memory gets stuck around 800Mb and that chunk never gets released. The problematic code is as follows:
executor = ThreadPoolExecutor(max workers = 1)
future_list = []
#Read converted images from directory(around 100 images in gray scale)
images = imread_collection(image_directory)
for i in range(0,len(images)-1,2):
img1 = images[i][:,:,0]
img2 = images[i+1][:,:,0]
future = executor.submit(process,xStart,yStart,xLen,yLen,img1,img2,i)
future_list.append(future)
#Wait or all tasks to finish
executor.shutdown(wait=True)
Memory consumption without Executor
Memory consumption using ThreadPool Executor
I've tested this in Mac and a Linux laptop before sending the code to the Raspberry. This issue is present in Linux but not in Mac.