''' 工做模式 Pipe的方法返回一個tuple (conn1,conn2) Pipe方法還有一個參數duplex參數,若是deplex 發消息: send 收消息:recv 關閉管道:close ''' import multiprocessing import time from multiprocessing import Process def proc1(pipe): for i in range(10): print("send {0}".format(i)) pipe.send(i) time.sleep(0.1) def proc2(pipe): n = 10 while n: print("proc2 recv: {0}".format(pipe.recv())) n -=1 if __name__ == '__main__': (p1,p2) = multiprocessing.Pipe(duplex=False) pr = Process(target=proc1,args=(p2,)) cu = Process(target=proc2,args=(p1,)) pr.start() cu.start()