Pipe进程之间的通信
#_author:来童星
#date:2019/12/11
#Pipe
from multiprocessing import Process, Pipe
def f(conn):
conn.send([42, None, 'hello'])
conn.close()
if __name__ == '__main__':
parent_conn, child_conn = Pipe()
p = Process(target=f, args=(child_conn,))
p.start()
print(parent_conn.recv()) #[42, None, 'hello']
p.join()
运行结果:
[42, None, 'hello']