title: Keep the code running while a video is displayed
body: <p>So I am trying to code up something that keeps a video running until a condition is met and some processes are done and new video is loaded immediately after these processes. These processes should continue without closing the current video and should only close the current video when the new video is loaded and ready for vizualization. </p>
  
  <p>This is best formulated by an example as given below: </p>
  
  <pre><code>import numpy as np 
  import os 
  import pygame 
  import cv2
  import time 
  
  def play_video(vid_loc):
      pygame.init()
      infos = pygame.display.Info()
      screen_size = (infos.current_w, infos.current_h)
  
      cap = cv2.VideoCapture(vid_loc) 
      frame_counter =0
      while(True):
  
          ret, frame = cap.read()
          frame_counter += 1
  
          if frame_counter == cap.get(cv2.CAP_PROP_FRAME_COUNT):
              frame_counter = 0 
              cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
  
          frame= cv2.resize(frame,screen_size)
          cv2.namedWindow('image', flags=cv2.WINDOW_GUI_NORMAL)
          cv2.setWindowProperty("image", cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
          cv2.imshow('image',frame)
  
          if cv2.waitKey(1000) &amp; 0xFF == ord('q'):
              break
  
      cap.release()
      cv2.destroyAllWindows()                
  
  vid_loc = ["home/odd.ogv", "home/even.ogv"]
  
  while True:
      n = random.randint(1, 100)
      if n%2 == 0:
          play_video(vid_loc[1])    
      else:
          play_video(vid_loc[0])
      time.sleep(10)
  </code></pre>
  
  <p>So this code generates a random number and checks if it is a even number or not. If even it runs a different video and if odd another video. My expectation with this code was to keep the random number being generated every
       10 second and keep the video running while the "while loop" runs again , generates another random number and checks if it is even or not without closing the video. If the number is odd , another video is run immediately after current video is closed. However this code would just keep the video running in loop as intended but does not generate another random number. </p>
  
  <p>It basically gets stuck at cv2.imshow until "q" key is pressed and only then the "while loop" runs again. </p>