title: MultiProcessing Pipe recv blocks even when child process is defunct
body: <p>Reading several questions on this topic I understand now that the child process inherits the file descriptors from the parent process. Which will make it more difficult for a child to receive an EOFError when a parent closes the connection.</p>
  
  <p>But my situation is the other way around, and I do not understand the problem I am facing.</p>
  
  <p>I have a parent process that starts a child process, and gives it access to one end of the Pipe connection I created. Now when the child process is done, malfunctions or whatever, everything is stopped and the connection is closed. At this point the child process shows to be defunct.</p>
  
  <p>Then I expect the parent process' connection to throw an EOFError on the blocking recv call. But instead it just sits there and waits.</p>
  
  <p>What am I missing here?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I think this example represents the problem:</p>
  
  <pre><code>from multiprocessing import Process, Pipe
  from threading import Thread
  import time
  
  class Parent(object):
  
      def __init__(self):
          self.parent_conn, child_conn = Pipe()
          self.child = Process(target=Child, args=(child_conn,))
          self.child.start()        
  
          def recv():
              try:
                  self.parent_conn.recv()
              except EOFError:
                  print "EOF"
              except:
                  print "something else"
  
          # Does not work
          recv()
  
          # Works fine
          t = Thread(target=recv)
          t.setDaemon(True)
          t.start()
  
      def close(self):
          self.parent_conn.close()
          self.child.join()
  
  class Child(object):
  
      def __init__(self, conn):
          conn.close()
  
  if __name__ == "__main__":
      p = Parent()
      time.sleep(1)
      p.close()
  </code></pre>
  
  <p>If I do use the separate thread, the parent is allowed to close its own connection and everything works fine. (Note that you still need to know somehow that the child is done for, to do this) Instead if I call recv directly it will block obviously, but I would suspect it to raise an EOFError as soon as the child process closes its connection. But it does not. Can anyone clarify?</p>