python 管道

 

#- * -coding: utf - 8 - * -
from multiprocessing import Process, Pipe

def f(conn):
    conn.send([42, None, 'hello'])
    while True:
        print(conn.recv())

if __name__ == '__main__':
    parent_conn, child_conn = Pipe()
    p = Process(target = f, args = (child_conn, ))
    p.start()
    print(parent_conn.recv())# prints "[42, None, 'hello']"
    parent_conn.send('666')
    p.terminate()

输出

[42, None, 'hello']

 

posted @ 2019-01-29 12:33  anobscureretreat  阅读(295)  评论(0编辑  收藏  举报