title: Python - Multiprocessing gets stuck after a while?
body: <p>So I have this Python script which uses Process from multiprocessing. It works great, but sometimes, randomly after 1-2 hours, the subprocess would hang and not terminate. This causes the program to get stuck. I'd have to restart it to get it to work again, just for this problem to occur again a few hours later. Please see the code below.</p>
  <pre><code>def scrollImageTransition(self, image_files, offset_x = 0, offset_y = 0, stocks = True):
      # use two image files and switch between them with a seemless transition
      current_img = 1
      image1 = self.openImage(image_files[0]).convert('RGB')
      image2 = self.openImage(image_files[1]).convert('RGB')
      
      double_buffer = self.matrix.CreateFrameCanvas()
      kill = False 
      while True:
          
          if current_img == 1:
              
              if stocks: 
                  update_process = Process(target = self.getFullStockImage, args = (1,))
                  update_process.start()
                  image1 = self.openImage(image_files[0]).convert('RGB')
                  image2 = self.openImage(image_files[1]).convert('RGB')
              
          elif current_img == 2:
             
              if stocks: 
                  update_process = Process(target = self.getFullStockImage, args = (2,))
                  update_process.start()
                  
                  image1 = self.openImage(image_files[1]).convert('RGB')
                  image2 = self.openImage(image_files[0]).convert('RGB')
          
          img_width, img_height = image1.size
          
          
          while offset_x &gt; -img_width:
              offset_x -= 1
              
              double_buffer.SetImage(image1, offset_x, offset_y)
              
              
              if offset_x + img_width &lt; self.matrix.width: # if the image is ending
                  double_buffer.SetImage(image2, offset_x, offset_y)
              
              double_buffer = self.matrix.SwapOnVSync(double_buffer)
              
              time.sleep(self.delay)
              kill = self.checkKilled()
              if kill: break
              
          if stocks:
              image1.close()
              image2.close()
                      
          if kill: break
          
          if stocks:
              update_process.join()
              update_process.terminate()
          if current_img == 1:
              current_img = 2 
          elif current_img == 2:
              current_img = 1 
          offset_x = 0
          update_process.join()
          update_process.terminate()
  </code></pre>