Python multiprocessing pipe will not recv() properly
Question: This is for Python 3.2.2. I'm only just learning how Python and
multiprocessing work and this simple example has been tripping me:

    
    
    from multiprocessing import Pipe, Process
    
    def f(r):
        print(r.recv())
    
    if __name__ == '__main__':
        q, r = Pipe()
        p = Process(target=f, args=(r,))
        p.start()
        q.send([42, None, 'hello'])
        p.join()
    

The main thread creates a new `Process`, `p`, and sends `r`, a bidirectional
connection object, to function `f()`. When process `p` is started, I expect
`r.recv()` to block (which, as far as I understand, means that this process
will wait indefinitely until something comes through the pipe) until the main
process sends some objects through with `q.send`.

Then `p.join()` should make the main process wait until `p` has run its
course.

But nothing whatsoever happens. If I add a `print` statement to `f()`, nothing
happens there, either, as if `f()` never even runs and `p.start()` is
nonfunctional.

Can you explain why this won't work and what might be fixed?


Answer: I know it's been a while, but for others with this problem, you have the ends
of your pipe reversed. You're trying to use the receiving end to send, and
trying to receive with the sending end. I find that adding duplex=True to the
Pipe constructor makes it much easier to deal with the different ends.

Source: <https://docs.python.org/2/library/multiprocessing.html#pipes-and-
queues>

