import multiprocessing
def initem(pipe): out,=pipe for item in range(10): out.send(item) out.close() def mulitem(pipe1,pipe2): close,inpipe=pipe1 close.close() out,=pipe2 try: while True: item=inpipe.recv() out.send(item*item) except: out.close() if name=="main": pipe1=multiprocessing.Pipe(True) pipe2=multiprocessing.Pipe(True) p1=multiprocessing.Process(target=initem,args=(pipe1,)) p1.start() p2=multiprocessing.Process(target=mulitem,args=(pipe1,pipe2)) p2.start() pipe1[0].close() pipe2[0].close() try: while True: print(pipe2[1].recv()) except: print("End")