title: python multiprocess queue with infinity loop
body: <p>I create 3 processes and want the function wirte1 to write value 'A,B,C' to queue1 ,and function read1 read value from queue1 and put it to queue2 ,in the same time, function read2 read value from queue2, but value B,C can't read from queue2 in time and the process finished.</p>
  <pre><code>from multiprocessing import Process, Queue,Manager,Pool,Lock
  import os, time, random
  
  #向队列1写数据
  def write1(q1,lock):
      lock.acquire()
      for value in ['A', 'B', 'C']:
          print ('Put %s to queue111...%s' % (value,str(os.getpid())))
          q1.put(value)
          time.sleep(1)
      lock.release()
  
  #从队列1读取数据并写入队列2
  def read1(q1,q2,lock):
      lock.acquire()
      while True:
          time.sleep(1)
          value=q1.get()
          # if value is None:break
          print('Get %s from queue111.%s' % (value,str(os.getpid())))
          q2.put(value)
          print('Put %s to queue222...%s' % (value,str(os.getpid())))
      lock.release()
  
  def read2(q2,lock):
      lock.acquire()
      while True:
          # if not q2.empty() or not q1.empty():
          time.sleep(2)
          value=q2.get(True)
          print('Get %s from queue222.%s' % (value,os.getpid()))
      lock.release()
  
  if __name__=='__main__':
      manager = Manager()
      # 父进程创建Queue，并传给各个子进程：
      q1 = manager.Queue()
      q2 = manager.Queue()
      lock1 = manager.Lock()
      lock2 = manager.Lock()
      lock3 = manager.Lock()
      start=time.time()
      p = Pool()
      # pw = p.apply_async(write1, args=(q1,lock1,))
      pw = Process(target=write1,args=(q1,lock1,))
      # time.sleep(0.5)
      # pr = p.apply_async(read1, args=(q1,q2,lock2,))
      # pr2 = p.apply_async(read2, args=(q2,lock3))
      pr=Process(target=read1,args=(q1,q2,lock2,))
      pr2 = Process(target=read2,args=(q2,lock3,))
  
      pw.start()
      pr.start()
      pr2.start()
  
      # p.close()
      # p.join()
      pw.join()
      pr.terminate()
      pr2.terminate()
  
  
      end=time.time()
      # print
      print('finished!!')
      print(end-start)
  </code></pre>
  <p>the output is:
  <code>    Put A to queue111...77678 Put B to queue111...77678 Get A from queue111.77680 Put A to queue222...77680 Put C to queue111...77678 Get A from queue222.77681 Get B from queue111.77680 Put B to queue222...77680 Get C from queue111.77680 Put C to queue222...77680 finished!! 3.025238275527954</code></p>