How to use threadpoolexecutor in infinite loop in python?

45 Views Asked by At

I am trying to make my program faster, using ThreadPoolExecutor. But this is not working it keeps closing without giving any error. I am using ThreadPoolExecutor in the while loop this might be a reason for the error.

Here is the code snippet:

from concurrent.futures import ThreadPoolExecutor as executor
import class1,class2,class3

pool = executor(5)
obj1= class1()
obj2= class2(arg)
obj3= class3(arg)
cap =cv2.VideoCapture(0)
while(cap.isOpened()):
    ret, frame = cap.read() 
    image = cv2.cvtColor(cv2.flip(frame,1),cv2.COLOR_BGR2RGB)

    if ret: 
        pool.submit(obj1.funct1,image)
        pool.submit(obj2.funct2,image =image,arg=arg)
        pool.submit(obj3.funct3,image =image,arg=arg)
                
    if cv2.waitKey(1) == 27:
        close_window(cap)
        pool.shutdown()
        break
0

There are 0 best solutions below