title: python hanging on closing/terminating multi-process task. Only stops via CTRL+Break
body: <p>I'm using multiprocess for screen grab to record keyboard actions and mouse movement associated with the image frame.</p>
  <p>After saving, imshow window is to close and the multi process task should terminate, however after saving and closing the imshow window my CMD prompt hangs until I CTRL+Break.</p>
  <p>If don't CTRL+Break and just close CMD prompt it appears the multi process task are still live in my task manager.</p>
  <p>I know I'm missing .join() and .close() I'm just unsure how to add them in. Every time I try I get VAR not defined. If anyone could take a look at my code and suggest changes that would be greatly appreciated.</p>
  <pre><code>import os
  import cv2
  import mss
  import time
  import pydirectinput
  import multiprocessing
  import numpy as np
  
  from utils.getkeys import key_check
  from distutils.version import StrictVersion
  from multiprocessing import Pipe
  
  win_title = &quot;ML Collection&quot;
  fps = 0
  fps_dptime = 2
  start_time = time.time()
  sct = mss.mss()
  
  image_data = &quot;./data/image_data.npy&quot;
  keyPress_data = &quot;./data/keyP_data.npy&quot;
  position_data = &quot;./data/pos_data.npy&quot;
  
  def create_data():
      if os.path.isfile(&quot;./data/image_data.npy&quot;):
          print(&quot;Loading previous data&quot;)
          img_data = list(np.load(image_data, allow_pickle=True))
          keyP_data = list(np.load(keyPress_data, allow_pickle=True))
          pos_data = list(np.load(position_data, allow_pickle=True))
      else:
          print(&quot;No previous files found. Creating new data files&quot;)
          img_data = []
          keyP_data = []
          pos_data = []
      return img_data, keyP_data, pos_data
  
  img_data, keyP_data, pos_data = create_data()
  
  def save_data(img_data, keyP_data, pos_data):
      np.save(image_data, img_data)
      np.save(keyPress_data, keyP_data)
      np.save(position_data, pos_data)
  
  
  def get_screen(s):
      while True:
        screen = np.array(
            sct.grab({&quot;top&quot;: 40, &quot;left&quot;: 0, &quot;width&quot;: 1280, &quot;height&quot;: 800})
            )
        s.put_nowait(screen)
        s.join()
        
  def mss_screen(s):
      global fps, start_time
      while True:
        if not s.empty():
          screen = s.get_nowait()
          s.task_done()
          screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
  ##        screen = cv2.Canny(screen, threshold1=119, threshold2=250)
          screen = cv2.resize(screen, (244, 244))
          cv2.imshow(win_title, screen)
  
          img_data.append(screen)
          keys = key_check()
          keyP_data.append(keys)
          mpos = pydirectinput.position()
          pos_data.append(mpos)
          
          fps+=1
          fpstime = time.time() - start_time
          if (fpstime) &gt;= fps_dptime :
            print(&quot;FPS: &quot;, fps / (fpstime))
            fps = 0
            start_time= time.time()
            print(&quot;Press Numpad+ to close&quot;)
          if cv2.waitKey(1) &amp; 0xFF == ord(&quot;+&quot;):
              cv2.destroyAllWindows()
              save_data(img_data, keyP_data, pos_data)
              s1.close()
              s2.close()
              break
          
  if __name__==&quot;__main__&quot;:
      s = multiprocessing.JoinableQueue()
  
      s1 = multiprocessing.Process(target=get_screen, args=(s,))
      s2 = multiprocessing.Process(target=mss_screen, args=(s,))  
  
      s1.start()
      s2.start()
  </code></pre>