Multi-process shared data, true communications manager

Source: Internet
Author: User

Managers

A Manager object returned by Manager() controls a server process which holds Python objects and allows other processes to Mani Pulate them using proxies.

A Manager returned byManager()Would support typeslist,dict,Namespace,Lock,RLock,Semaphore,BoundedSemaphore,Condition,Event,Barrier,Queue,ValueandArray. For example,

From multiprocessing import Process,managerimport threading,time,osdef sub (d,l):    d[os.getpid ()] = Os.getpid ()    L.append (Os.getppid ())    print (L)    #print (d) if __name__ = = ' __main__ ': With    Manager () as M: #with. As is the role of the manager () to generate an alias M, and only in with the effective        d = m.dict ()    #用了with, the following can also be used.        L = Manager (). List (range (5))        p_list = []    #这个列表保存生成的多个进程, facilitates a join (). Wait for all to complete, for        i in range:            t = Process (target=sub,args= (d,l))            T.start ()            p_list.append (t)        For i in P_list:            i.join ()        print (d,l)

...

Multi-process shared data, true communications manager

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.