Multi-process-pipe and manager data sharing and delivery

Source: Internet
Author: User

pipe.py# multi-process data delivery receive and send (like socket)

From  multiprocessing import process,pipedef F (conn):    conn.send ([42,none, "Hello to Child"])    conn.send ( [All, None, "Hello from Child2"])    Print ("From parent:", CONN.RECV ()) If __name__ = = ' __main__ ':    parent_conn, child_conn= Pipe ()    p=process (target =f,args= (Child_conn,))    P.start ()    print (PARENT_CONN.RECV ())    print (PARENT_CONN.RECV ())    Parent_ Conn.send ("Dog fat Bites you!") ")    P.join ()

manger.py# data sharing and delivery across multiple processes (while modifying one copy of the data)

From multiprocessing import Process,managerimport osdef F (d,l): D[os.getpid ()]=os.getpid (    )    l.append ( Os.getpid ())    print (l) if __name__ = = "__main__": With    Manager () as manager:        d= manager.dict () # Generate a dictionary to share a single copy of data and pass in multiple processes        L =manager.list (range (5)) #生成一个列表可在多个进程中共享一份数据和传递        p_list =[] for        i in range (10):            P =process (target=f,args= (d,l))            P.start ()            p_list.append (p) for        res in p_list:            res.join ()        print (d)        print (L)

Multi-process-pipe and manager data sharing and delivery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.