title: python - How to Handle Multithreading in loop
body: <p>The below is the logic which is implemented.But here since it is infinite loop until and unless we break the loop the threads which are in the loop are unable to kill.Since these are in the loop the process memory is getting increased.How to kill a thread when function is completed.Is there any other procedure to implement this ?</p>
  
  <pre><code> def sample(args):
         //Complex Functionality which it processes a image and stores in a folder
  
     def Camera():
       cap = cv2.VideoCapture(0)
       threads = []
       while(True):
           ret,frame = cap.read()
           t1= threading.Thread(target=sample, args=(frame,))
           t1.start()
           threads.append(t1)
           if cv2.waitKey(1) &amp; 0xFF == ord('q'):
                  break
      for t2 in threads:
        t2.join()
  </code></pre>
  
  <p>I dont want to pause the main loop for the thread to complete the functionality</p>