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()
  • 相关阅读:
    hdu Can you solve this equation
    hdu cup
    hdu Line belt
    三分搜索法
    hdu Strange fuction
    HDU 1175 连连看
    loadView、viewDidLoad及viewDidUnload的关系
    iOS图片拉伸技巧
    iOS完整学习路线图
    Core Data入门
  • 原文地址:https://www.cnblogs.com/rongye/p/9982261.html
Copyright © 2011-2022 走看看