Why my process cannot terminate when Pipe Connection is closed

Ke Wang kw429 at cornell.edu
Wed Jun 22 18:49:56 EDT 2016


import multiprocessing as mp


def send(conn):
    """send obj to pipe"""
    for i in range(10):
        conn.send(i)
        print("send:", i)
    conn.close()


def transform(func, conn):
    """receive input from pipe, transform it"""
    try:
        while True:
            i = conn.recv()
            print('transform:', func(i))
    except EOFError:
        conn.close()


c_1, c_2 = mp.Pipe()
p1 = mp.Process(target=send, args=(c_1,))
p2 = mp.Process(target=transform, args=(lambda x: x ** 2, c_2,))

p1.start()
p2.start()
p1.join()
p2.join()


In python documentation it's stated, recv() Blocks until there its something to receive. Raises EOFError if there is nothing left to receive and the other end was closed.

But why this code doesn't terminate?





More information about the Python-list mailing list