zoukankan      html  css  js  c++  java
  • 进程 pipe


    from multiprocessing import Process, Pipe


    def f(conn):
    conn.send([42, None, 'hello from child'])
    conn.send([42, None, 'hello from child3'])
    print("",conn.recv())
    conn.close()


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

    #===========================
    from multiprocessing import Process, Pipe


    def f(conn):
    conn.send([42, None, 'hello from child'])
    conn.send([42, None, 'hello from child2'])
    print("from parent:",conn.recv())
    conn.close()

    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']"
    print(parent_conn.recv()) # prints "[42, None, 'hello']"
    parent_conn.send("张洋可好") # prints "[42, None, 'hello']"
    p.join()
  • 相关阅读:
    [USACO17JAN]Subsequence Reversal序列反转
    P1330 封锁阳光大学
    P1403 [AHOI2005]约数研究
    poj1456——Supermarket
    P1807 最长路_NOI导刊2010提高(07)
    P1137 旅行计划
    P1162 填涂颜色
    P1040 加分二叉树
    P1135 奇怪的电梯
    P1086 花生采摘
  • 原文地址:https://www.cnblogs.com/rongye/p/9982261.html
Copyright © 2011-2022 走看看