title: Accessing two webcams using multiprocessing in python to display on pygame surface simultaneously
body: <p>I'm working on my academic project. I've to display outputs from two webcams onto the screen simultaneously without lag. For that, I'm using pygame surface(because it is SDL) and multiprocessing in python. Using multiprocessing we can only able to pipe one object between two processes only.
  Here is my expected code to be run:</p>
  
  <pre><code>#!/usr/bin/python
  import os, sys
  from multiprocessing import Process
  import time
  import pygame
  import Tkinter as tk
  import pygame.camera
  from pygame.locals import *
  
  # Initializations
  
  pygame.init()
  pygame.camera.init()
  pygame.display.init()
  
  w= 320
  h = 240
  fps = 45
  
  clist = pygame.camera.list_cameras()
  screen = pygame.display.set_mode((w*2,h))
  
  def cam1_core():
     print 'left started'
     writer1 = imageio.get_writer('left_eye.avi', fps=fps)
     cam1 = pygame.camera.Camera(clist[0], (w, h))
     cam1.start()
     time.sleep(1)
     i=0
     while i &lt; 500:
        imgb = cam1.get_image()
        img1 = pygame.surfarray.array3d(imgb)
        screen.blit(imgb, (0, 0))
        pygame.display.update()
        i = i + 1
        #sys.stdout.flush()
     cam1.stop()
  
     sys.stdout.flush()
  
  
  def cam2_core():
     print 'right started'
     cam2 = pygame.camera.Camera(clist[1], (w, h))
     cam2.start()
     time.sleep(1)
     j=0
     while j &lt; 500:
        imga = cam2.get_image()
        img2 = pygame.surfarray.array3d(imga)
        screen.blit(imga, (w, 0))
        pygame.display.update()
        j = j + 1
        #sys.stdout.flush()
     cam2.stop()
  
     print 'right closed'
     sys.stdout.flush()
  
  if __name__ == '__main__':
      p1 = Process(target=cam1_core)
      p2 = Process(target=cam2_core)
      p1.start()
      p2.start()
  </code></pre>
  
  <p>I know this code won't work but something similar like piping pygame-surface object to cam1_core and cam2_core processes (but pipes have only one start point and one end point also it is not a good idea to pipe/queue objects between processes) or piping/queue camera images to display. I'm using multiprocessing to get images simultaneously. Any relevant information for this kind of problem is highly appreciated.</p>