title: Why are Python multiprocessing Pipe unsafe?
body: <p>I don't understand why <a href="http://docs.python.org/library/multiprocessing.html#multiprocessing.Pipe" rel="noreferrer"><code>Pipes</code></a> are said unsafe when there are multiple senders and receivers.</p>
  
  <p>How the following code can be turned into code using <a href="http://docs.python.org/library/multiprocessing.html#multiprocessing.Queue" rel="noreferrer"><code>Queues</code></a> if this is the case ? <code>Queues</code> don't throw <code>EOFError</code> when closed, so my processes can't stop. Should I send endlessly 'Poison' messages to tell them to stop (this way, i'm sure all my processes receive at least one poison) ?</p>
  
  <p>I would like to keep the pipe <code>p1</code> open until I decide otherwise (here it's when I have sent the 10 messages). </p>
  
  <hr>
  
  <pre><code>from multiprocessing import Pipe, Process
  from random import randint, random
  from time import sleep
  
  def job(name, p_in, p_out):
      print(name + ' starting')
      nb_msg = 0
      try:
          while True:
              x = p_in.recv()
              print(name + ' receives ' + x)
              nb_msg = nb_msg + 1
              p_out.send(x)
              sleep(random())
      except EOFError:
          pass
      print(name + ' ending ... ' + str(nb_msg) + ' message(s)')
  
  if __name__ == '__main__':
      p1_in, p1_out = Pipe()
      p2_in, p2_out = Pipe()
  
      proc = []
  
      for i in range(3):
          p = Process(target=job, args=(str(i), p1_out, p2_in))
          p.start()
          proc.append(p)
  
      for x in range(10):
          p1_in.send(chr(97+x))
      p1_in.close()
      for p in proc:
          p.join()
      p1_out.close()
      p2_in.close()
  
      try:
          while True:
              print(p2_out.recv())
      except EOFError:
          pass
  
      p2_out.close()
  </code></pre>