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
,Value
andArray
. 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