U e5d@sBdddddgZddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z d d l m Z d d l mZmZmZd d l mZd d l mZd dl mZd dl mZzd dl mZdZWnek rdZYnXddZeejedddDZedek r.ddZeD]ZeeeqGdddeZdifddZ ddZ!Gd d!d!e"Z#d"d#Z$d$d%Z%Gd&d'd'eZ&Gd(d)d)eZ'e j(e j)fe j*e j+fd*Z,Gd+ddeZ-Gd,d-d-e.Z/Gd.ddeZ0d/d0Z1ifd1d2Z2dld3d4Z3Gd5d6d6eZ4Gd7d8d8eZ5dmd9d:Z6Gd;d<dd>e0Z8Gd?d@d@e8Z9GdAdBdBe0Z:GdCdDdDe0Z;GdEdFdFe0ZGdKdLdLe>Z?e2dMdNZ@dOdPie@_Ae2dQdRZBe2dSdTZCdUdUdUdPdPdVeC_AGdWdSdSeCZDGdXdde-ZEeEdYejFeEdZejFeEd[ejGe:eEd\ejHe8eEd]ejIe8eEd^ejJe8eEd_ejKe8eEd`ejLe9eEdaejMe;eEdbejNeDeEdcee?eEddeOe@eEd8e5e=eEd:e6eBeEd6e4e<eEjdPe7ddeeEjdUddfer>GdgdhdhZPGdidjdje&ZQGdkdde-ZRdS)n BaseManager SyncManager BaseProxyTokenSharedMemoryManagerN)getpid) format_exc) connection) reductionget_spawning_popen ProcessError)pool)process)util) get_context) shared_memoryTFcCstj|j|ffSN)arraytypecodetobytes)ar0/usr/lib64/python3.8/multiprocessing/managers.py reduce_array-srcCsg|]}tti|qSr)typegetattr.0namerrr 1sr )itemskeysvaluescCstt|ffSr)listobjrrrrebuild_as_list3sr'c@s4eZdZdZdZddZddZddZd d Zd S) rz3 Type to uniquely identify a shared object typeidaddressidcCs||||_|_|_dSrr()selfr)r*r+rrr__init__BszToken.__init__cCs|j|j|jfSrr(r,rrr __getstate__EszToken.__getstate__cCs|\|_|_|_dSrr(r,staterrr __setstate__HszToken.__setstate__cCsd|jj|j|j|jfS)Nz %s(typeid=%r, address=%r, id=%r)) __class____name__r)r*r+r.rrr__repr__KszToken.__repr__N) r4 __module__ __qualname____doc__ __slots__r-r/r2r5rrrrr<s rcCs8|||||f|\}}|dkr*|St||dS)zL Send a message to manager using connection `c` and return response #RETURNN)sendrecvconvert_to_error)cr+ methodnameargskwdskindresultrrrdispatchSs  rDcCsd|dkr |S|dkrRt|ts4td||t||dkrHtd|St|Sntd|SdS)N#ERROR) #TRACEBACK#UNSERIALIZABLEz.Result {0!r} (kind '{1}') type is {2}, not strrGzUnserializable message: %s zUnrecognized message type {!r}) isinstancestr TypeErrorformatr RemoteError ValueError)rBrCrrrr=]s   r=c@seZdZddZdS)rLcCsdt|jddS)NzM --------------------------------------------------------------------------- rzK---------------------------------------------------------------------------)rIr@r.rrr__str__mszRemoteError.__str__N)r4r6r7rNrrrrrLlsrLcCs2g}t|D] }t||}t|r ||q |S)z4 Return a list of names of methods of `obj` )dirrcallableappend)r&temprfuncrrr all_methodsts    rTcCsddt|DS)zP Return a list of names of methods of `obj` which do not start with '_' cSsg|]}|ddkr|qS)r_rrrrrr s z"public_methods..)rTr%rrrpublic_methodssrVc @seZdZdZdddddddd d g Zd d Zd dZddZddZddZ ddZ ddZ ddZ e e e dZ ddZddZd d!Zd"d#Zd$d%Zd&e_d'd(Zd)d*Zd+d,Zd-d.Zd/S)0ServerzM Server class which runs in a process controlled by a manager object shutdowncreateaccept_connection get_methods debug_infonumber_of_objectsdummyincrefdecrefcCsxt|tstd|t|||_t||_t |\}}||dd|_ |j j |_ ddi|_ i|_ i|_t|_dS)Nz&Authkey {0!r} is type {1!s}, not bytes)r*Zbacklog0Nr)rHbytesrJrKrregistryrAuthenticationStringauthkeylistener_clientlistenerr* id_to_objid_to_refcountid_to_local_proxy_obj threadingLockmutex)r,rer*rg serializerListenerClientrrrr-s      zServer.__init__c Cst|_|t_zVtj|jd}d|_|z|jsL|jdq4Wnttfk rfYnXW5tjtjkrt dtjt_tj t_ t dXdS)z( Run the server forever zresetting stdout, stderrr)targetTr N)rmEvent stop_eventrcurrent_process_manager_serversysstdout __stdout__rdebug __stderr__stderrexitThreadaccepterdaemonstartis_setwaitKeyboardInterrupt SystemExit)r,rrrr serve_forevers       zServer.serve_forevercCsNz|j}Wntk r&YqYnXtj|j|fd}d|_|qdS)Nrsr@T)riZacceptOSErrorrmrhandle_requestrr)r,r>trrrrs zServer.accepterc CsLd}}}zTt||jt||j|}|\}}}}||jksTtd|t||}Wntk r~dt f} Yn>Xz||f||}Wntk rdt f} Yn Xd|f} z| | Wnttk r>} zTz| dt fWntk rYnXt d| t d|t d| W5d} ~ XYnX| dS)z) Handle a new connection Nz%r unrecognizedrFr:zFailure to send message: %rz ... request was %r ... exception was %r)r Zdeliver_challengergZanswer_challenger<publicAssertionErrorr Exceptionrr;rinfoclose) r,r>funcnamerCrequestignorer@rArSmsgerrrrs4    zServer.handle_requestc Cstdtj|j}|j}|j}|j szBd}}|}|\}}} } z||\}} } Wn^t k r} z@z|j |\}} } Wn&t k r}z| W5d}~XYnXW5d} ~ XYnX|| krt d|t || ft||}z|| | }Wn,tk r"}z d|f}W5d}~XYnPX| o4| |d}|rj||||\}}t||j|}d||ff}nd|f}Wnt k r|dkrdtf}nNz,|j|}|||||f| | }d|f}Wn tk rdtf}YnXYnPtk rtdtjtd Yn tk r<dtf}YnXzDz ||Wn2tk r~}z|d tfW5d}~XYnXWq$tk r}z@td tjtd |td ||tdW5d}~XYq$Xq$dS)zQ Handle requests from the proxies in a particular process/thread z$starting server thread to service %rNz+method %r of %r object is not in exposed=%rrE#PROXYr:rFz$got EOF -- exiting thread serving %rrrGzexception in thread serving %rz ... message was %rrr )rr{rmcurrent_threadrr<r;rjrurKeyErrorrlAttributeErrorrrrgetrYrr*rfallback_mappingEOFErrorrxr~rr)r,connr<r;rjr?r&ridentr@rAexposed gettypeidkeZ second_keZfunctionresrrr)ZridentZrexposedtokenZ fallback_funcrCrrr serve_clients   (        $  zServer.serve_clientcCs|Srrr,rrr&rrrfallback_getvalue5szServer.fallback_getvaluecCst|SrrIrrrr fallback_str8szServer.fallback_strcCst|Sr)reprrrrr fallback_repr;szServer.fallback_repr)rNr5 #GETVALUEcCsdSrrr,r>rrrr^Dsz Server.dummyc Cs|jtg}t|j}||D]<}|dkr&|d||j|t|j|dddfq&d|W5QRSQRXdS)zO Return some info --- useful to spot problems with refcounting rbz %s: refcount=%s %srNK ) ror$rkr"sortrQrIrjjoin)r,r>rCr"rrrrr\Gs zServer.debug_infocCs t|jS)z* Number of shared objects )lenrkrrrrr]WszServer.number_of_objectscCsLz:ztd|dWnddl}|YnXW5|jXdS)z' Shutdown this process z!manager received shutdown messager:NrN)rusetrr{r; traceback print_exc)r,r>rrrrrX^s zServer.shutdownc Ost|dkr|^}}}}n|s(tdnd|krDtdt|d|d}t|dkr~|^}}}ddl}|jd tdd nFd |krtdt|d|d }|^}}ddl}|jd tdd t|}|j|j|\}}}} |dkr|st|dkr t d |d} n |||} |dkr2t | }|dk rlt |t s\td |t|t|t|}dt| } td|| | t||f|j| <| |jkrd|j| <W5QRX||| | t|fS)z> Create a new shared object and return its id z8descriptor 'create' of 'Server' object needs an argumentr)7create expected at least 2 positional arguments, got %dr rNz2Passing 'typeid' as keyword argument is deprecated) stacklevelr>z-Passing 'c' as keyword argument is deprecatedz4Without callable, must have one non-keyword argumentz,Method_to_typeid {0!r}: type {1!s}, not dictz%xz&%r callable returned object with id %r)rrJpopwarningswarnDeprecationWarningtuplerorerMrVrHdictrKrr$r+rr{rrjrkr_) r@rAr,r>r)rrPrmethod_to_typeid proxytyper&rrrrrYksp                  z Server.createz$($self, c, typeid, /, *args, **kwds)cCst|j|jdS)zL Return the methods of the shared object indicated by token r )rrjr+)r,r>rrrrr[szServer.get_methodscCs"|t_|d||dS)z= Spawn a new thread to serve this connection rN)rmrrr;r)r,r>rrrrrZs  zServer.accept_connectionc Cs|jz|j|d7<Wnhtk r}zJ||jkrrd|j|<|j||j|<|j|\}}}td|n|W5d}~XYnXW5QRXdS)Nr z&Server re-enabled tracking & INCREF %r)rorkrrlrjrr{)r,r>rrr&rrrrrr_s  z Server.increfc Cs||jkr$||jkr$td|dS|jZ|j|dkrXtd||j||j||j|d8<|j|dkr|j|=W5QRX||jkrd|j|<td||j|j|=W5QRXdS)NzServer DECREF skipping %rrz+Id {0!s} ({1!r}) has refcount {2:n}, not 1+r )NrNzdisposing of obj with id %r)rkrlrr{rorrKrj)r,r>rrrrr`s,     z Server.decrefN)r4r6r7r8rr-rrrrrrrrr^r\r]rXrY__text_signature__r[rZr_r`rrrrrWs< "Q =rWc@seZdZdgZdZdZdZdS)Statevaluerr rN)r4r6r7r9INITIALSTARTEDSHUTDOWNrrrrrsr)pickleZ xmlrpclibc@seZdZdZiZeZd"ddZddZdd Z d#d d Z e d$d dZ ddZ d%ddZddZddZddZddZeddZeddZe d&d d!ZdS)'rz! Base class for managers NrcCs\|dkrtj}||_t||_t|_tj|j_ ||_ t |\|_ |_ |pTt|_dSr)rrvrg_addressrf_authkeyr_staterr _serializerrhZ _Listener_Clientr_ctx)r,r*rgrpZctxrrrr-s   zBaseManager.__init__cCsf|jjtjkrP|jjtjkr&tdn*|jjtjkr>tdntd|jjt|j |j |j |j S)zX Return server object with serve_forever() method and address attribute Already started serverManager has shut downUnknown state {!r}) rrrrrr rrKrW _registryrrrr.rrr get_servers    zBaseManager.get_servercCs8t|j\}}||j|jd}t|ddtj|j_dS)z> Connect manager object to the server process rgNr^) rhrrrrDrrrr)r,rqrrrrrrconnects zBaseManager.connectrc Cs4|jjtjkrP|jjtjkr&tdn*|jjtjkr>tdntd|jj|dk rht|sht dt j dd\}}|j j t|j|j|j|j|j|||fd|_d d d |jjD}t|jd ||j_|j|||_|tj|j_tj|t|j|j|j|j|j|jfd d|_ dS)z@ Spawn a server process for this manager object rrrNzinitializer must be a callableF)Zduplexr:css|]}t|VqdSrr)rirrr Asz$BaseManager.start..-rr@Z exitpriority)!rrrrrr rrKrPrJr ZPiperZProcessr _run_serverrrrr_processrZ _identityr4rrrr<rFinalize_finalize_managerrrX)r, initializerinitargsreaderwriterrrrrr(sH        zBaseManager.startc Cs^ttjtj|dk r |||||||}||j|td|j| dS)z@ Create a server, report its address and run it Nzmanager serving at %r) signalSIGINTSIG_IGN_Serverr;r*rrrr) clsrer*rgrprrrserverrrrrSs zBaseManager._run_servercOsd|jjtjkstd|j|j|jd}zt |dd|f||\}}W5|Xt ||j||fS)zP Create a new shared object; return the token and exposed tuple zserver not yet startedrNrY) rrrrrrrrrrDr)r,r)r@rArr+rrrr_createjs  zBaseManager._createcCs*|jdk r&|j||js&d|_dS)zC Join the manager process (if it has been spawned) N)rris_aliver,timeoutrrrrvs   zBaseManager.joincCs2|j|j|jd}zt|ddWS|XdS)zS Return some info about the servers shared objects and connections rNr\rrrrrDr,rrrr _debug_infoszBaseManager._debug_infocCs2|j|j|jd}zt|ddWS|XdS)z5 Return the number of shared objects rNr]rrrrr_number_of_objectsszBaseManager._number_of_objectscCsj|jjtjkr||jjtjkrf|jjtjkr.temp) __dict__rcopy AutoProxyrr$r!rrIrr4setattr) rr)rPrrr create_methodkeyrrRrrrregisters*     zBaseManager.register)NNrN)Nr)Nr)N)NNNNT)r4r6r7r8rrWrr-rrr classmethodrrrrrrr staticmethodrpropertyr*rrrrrrs8  +       c@seZdZddZddZdS)ProcessLocalSetcCst|dddS)NcSs|Sr)clearr%rrrz*ProcessLocalSet.__init__..)rregister_after_forkr.rrrr-szProcessLocalSet.__init__cCs t|dfSrc)rr.rrr __reduce__szProcessLocalSet.__reduce__N)r4r6r7r-rrrrrr sr c@seZdZdZiZeZdddZddZ d ifd d Z d d Z ddZ e ddZddZddZddZddZddZdS)rz. A base for proxies of shared objects NTFc Cstj8tj|jd}|dkr:ttf}|tj|j<W5QRX|d|_|d|_ ||_ |j j |_ ||_ ||_t|d|_||_|dk rt||_n"|j dk r|j j|_n tj|_|r|t|tjdS)Nrr )r_mutexrrr*rZForkAwareLocalr _tls_idset_tokenr+_id_managerrrhr_owned_by_managerrrfrrvrg_increfr  _after_fork) r,rrprrgrr_ manager_ownedZ tls_idsetrrrr-s*      zBaseProxy.__init__cCsdtdtj}tjdkr4|dtj7}|j|jj |j d}t |dd|f||j _ dS)Nzmaking connection to managerZ MainThread|rrZ)rr{rrvrrmrrrr*rrDrr )r,rrrrr_connect-s  zBaseProxy._connectrc Csz |jj}Wn6tk rBtdtj||jj}YnX| |j |||f| \}}|dkrp|S|dkr|\}}|j j |jd} |jj|_| ||j|j |j|d} |j|j|jd}t|dd|jf| St||dS) zV Try to call a method of the referent and return a copy of the result z#thread %r does not own a connectionr:rrrNr`)rr rrr{rmrrrr;rr<rrr)rr*rrrrDr+r=) r,r?r@rArrBrCrrrrrrr _callmethod6s6   zBaseProxy._callmethodcCs |dS)z9 Get a copy of the value of the referent rrr.rrr _getvalueTszBaseProxy._getvaluec Cs|jrtd|jjdS|j|jj|jd}t|dd|j ftd|jj|j |j |j oj|j j }tj|tj|j|j||j|j |jfdd|_dS)Nz%owned_by_manager skipped INCREF of %rrr_z INCREF %r r)rrr{rr+rr*rrDrraddrrrr_decrefrZ_close)r,rr1rrrrZs$ zBaseProxy._increfc Cs||j|dks |jtjkrz2td|j||j|d}t|dd|jfWqt k r}ztd|W5d}~XYqXntd|j|st |drtdt j |j|`dS)Nz DECREF %rrr`z... decref failed %sz%DECREF %r -- manager already shutdownr z-thread %r has no more proxies so closing conn)discardr+rrrrr{r*rDrrrmrrr r)rrgr1ZtlsZidsetrrrrrrr!ns   zBaseProxy._decrefc CsHd|_z |Wn0tk rB}ztd|W5d}~XYnXdS)Nzincref failed: %s)rrrrr)r,rrrrrs  zBaseProxy._after_forkcCs^i}tdk r|j|d<t|ddrB|j|d<tt|j|j|ffStt||j|j|ffSdS)Nrg_isautoFr) r rrr RebuildProxyrrrrr,rArrrrs    zBaseProxy.__reduce__cCs|Sr)r)r,Zmemorrr __deepcopy__szBaseProxy.__deepcopy__cCsdt|j|jjt|fS)Nz<%s object, typeid %r at %#x>)rr4rr)r+r.rrrr5szBaseProxy.__repr__cCs:z |dWStk r4t|dddYSXdS)zV Return representation of the referent (or a fall-back if that fails) r5Nrz; '__str__()' failed>)rrrr.rrrrNs zBaseProxy.__str__)NNNTF)r4r6r7r8rrZForkAwareThreadLockrr-rrrrrr!rrr&r5rNrrrrrs( )   cCsttdd}|rT|j|jkrTtd|d|d<|j|jkrT|j|j|j|j<| ddopttdd }|||fd|i|S) z5 Function used for unpickling proxy objects. rwNz*Rebuild a proxy owned by manager, token=%rTrr_Z _inheritingF) rrrvr*rr{r+rlrjr)rSrrprArr_rrrr$s    r$cCspt|}z|||fWStk r*YnXi}|D]}td||f|q4t|tf|}||_||||f<|S)zB Return a proxy type whose methods are given by `exposed` zOdef %s(self, /, *args, **kwds): return self._callmethod(%r, args, kwds))rrexecrrr)rr_cacheZdicZmeth ProxyTyperrr MakeProxyTypes  r*c Cst|d}|dkrB||j|d}zt|dd|f}W5|X|dkrX|dk rX|j}|dkrjtj}td|j |}||||||d} d| _ | S)z* Return an auto-proxy for `token` r Nrr[z AutoProxy[%s])rrgr_T) rhr*rrDrrrvrgr*r)r#) rrprrgrr_rrr)rrrrrs     rc@seZdZddZddZdS) NamespacecKs|j|dSr)rupdater%rrrr-szNamespace.__init__cCsZt|j}g}|D]$\}}|ds|d||fq|d|jjd|fS)NrUz%s=%rz%s(%s)z, ) r$rr! startswithrQrr3r4r)r,r!rRrrrrrr5s  zNamespace.__repr__N)r4r6r7r-r5rrrrr+sr+c@s8eZdZd ddZddZddZdd ZeeeZd S) ValueTcCs||_||_dSr) _typecode_value)r,rrlockrrrr-szValue.__init__cCs|jSrr0r.rrrrsz Value.getcCs ||_dSrr2r,rrrrr sz Value.setcCsdt|j|j|jfS)Nz %s(%r, %r))rr4r/r0r.rrrr5 szValue.__repr__N)T) r4r6r7r-rrr5rrrrrrr.s  r.cCs t||Sr)r)rsequencer1rrrArraysr5c@s8eZdZdZddZddZddZdd Zd d Zd S) IteratorProxy)__next__r;throwrcCs|Srrr.rrr__iter__szIteratorProxy.__iter__cGs |d|S)Nr7rr,r@rrrr7szIteratorProxy.__next__cGs |d|S)Nr;rr:rrrr;szIteratorProxy.sendcGs |d|S)Nr8rr:rrrr8szIteratorProxy.throwcGs |d|S)Nrrr:rrrr!szIteratorProxy.closeN) r4r6r7rr9r7r;r8rrrrrr6s r6c@s2eZdZdZd ddZddZdd Zd d ZdS) AcquirerProxy)acquirereleaseTNcCs"|dkr|fn||f}|d|SNr<r)r,Zblockingrr@rrrr<'szAcquirerProxy.acquirecCs |dSNr=rr.rrrr=*szAcquirerProxy.releasecCs |dSr>rr.rrrr,szAcquirerProxy.__enter__cCs |dSr?rrrrrr.szAcquirerProxy.__exit__)TN)r4r6r7rr<r=rrrrrrr;%s  r;c@s6eZdZdZd ddZd ddZdd Zdd d ZdS)ConditionProxy)r<r=rnotify notify_allNcCs|d|fSNrrrrrrr4szConditionProxy.waitr cCs|d|fS)NrAr)r,nrrrrA6szConditionProxy.notifycCs |dS)NrBrr.rrrrB8szConditionProxy.notify_allcCsd|}|r|S|dk r$t|}nd}d}|s`|dk rN|t}|dkrNq`|||}q,|S)Nr)time monotonicr)r,Z predicaterrCZendtimeZwaittimerrrwait_for:s  zConditionProxy.wait_for)N)r )N)r4r6r7rrrArBrGrrrrr@2s   r@c@s2eZdZdZddZddZddZd d d ZdS) EventProxy)rrr rcCs |dS)Nrrr.rrrrOszEventProxy.is_setcCs |dSNrrr.rrrrQszEventProxy.setcCs |dS)Nr rr.rrrr SszEventProxy.clearNcCs|d|fSrCrrrrrrUszEventProxy.wait)N)r4r6r7rrrr rrrrrrHMs rHc@sNeZdZdZdddZddZddZed d Zed d Z ed dZ dS) BarrierProxy)__getattribute__rabortresetNcCs|d|fSrCrrrrrr[szBarrierProxy.waitcCs |dS)NrLrr.rrrrL]szBarrierProxy.abortcCs |dS)NrMrr.rrrrM_szBarrierProxy.resetcCs |ddS)NrK)partiesrr.rrrrNaszBarrierProxy.partiescCs |ddS)NrK) n_waitingrr.rrrrOdszBarrierProxy.n_waitingcCs |ddS)NrK)brokenrr.rrrrPgszBarrierProxy.broken)N) r4r6r7rrrLrMrrNrOrPrrrrrJYs   rJc@s(eZdZdZddZddZddZdS) NamespaceProxy)rK __setattr__ __delattr__cCs0|ddkrt||St|d}|d|fS)NrrUrrK)objectrKr,r callmethodrrr __getattr__ns   zNamespaceProxy.__getattr__cCs4|ddkrt|||St|d}|d||fS)NrrUrrR)rTrRrK)r,rrrVrrrrRss  zNamespaceProxy.__setattr__cCs0|ddkrt||St|d}|d|fS)NrrUrrS)rTrSrKrUrrrrSxs   zNamespaceProxy.__delattr__N)r4r6r7rrWrRrSrrrrrQlsrQc@s*eZdZdZddZddZeeeZdS) ValueProxy)rrcCs |dS)Nrrr.rrrrszValueProxy.getcCs|d|fSrIrr3rrrrszValueProxy.setN)r4r6r7rrrrrrrrrrXsrX BaseListProxy)__add__ __contains__ __delitem__ __getitem____len____mul__ __reversed____rmul__ __setitem__rQcountextendindexinsertrremovereverser__imul__c@seZdZddZddZdS) ListProxycCs|d|f|S)Nrdrr3rrr__iadd__szListProxy.__iadd__cCs|d|f|S)Nrirr3rrrriszListProxy.__imul__N)r4r6r7rkrirrrrrjsrj DictProxy)r[r\r]r9r^rbr rrr!r"rpopitem setdefaultr,r#r9Iterator ArrayProxy)r^r]rb PoolProxy) Zapply apply_asyncrimapimap_unorderedrmap map_asyncstarmap starmap_asyncrZ AsyncResult)rrrvrxrsrtc@seZdZddZddZdS)rqcCs|Srrr.rrrrszPoolProxy.__enter__cCs |dSr)rrrrrrszPoolProxy.__exit__N)r4r6r7rrrrrrrqsc@seZdZdZdS)ra( Subclass of `BaseManager` which supports a number of shared object types. The types registered are those intended for the synchronization of threads, plus `dict`, `list` and `Namespace`. The `multiprocessing.Manager()` function creates started instances of this class. N)r4r6r7r8rrrrrsQueueZ JoinableQueuertrnRLock SemaphoreBoundedSemaphore ConditionBarrierPoolr$r)rr)rc@sLeZdZdZgfddZddZddZdd Zd d Zd d Z ddZ dS)_SharedMemoryTrackerz+Manages one or more shared memory segments.cCs||_||_dSrZshared_memory_context_name segment_names)r,rrrrrr-sz_SharedMemoryTracker.__init__cCs(td|dt|j|dS)z6Adds the supplied shared memory block name to tracker.zRegister segment  in pid N)rr{rrrQr, segment_namerrrregister_segmentsz%_SharedMemoryTracker.register_segmentcCsBtd|dt|j|t|}||dS)zCalls unlink() on the shared memory block with the supplied name and removes it from the list of blocks being tracked.zDestroy segment rN) rr{rrrgr SharedMemoryrunlink)r,rZsegmentrrrdestroy_segments   z$_SharedMemoryTracker.destroy_segmentcCs"|jddD]}||qdS)zrrrrr.sz SharedMemoryServer.track_segmentcCs|j|dS)zCalls unlink() on the shared memory block with the supplied name and removes it from the tracker instance inside the Server.N)rrrrrrr2sz"SharedMemoryServer.release_segmentcCs|jjS)zbReturns a list of names of shared memory blocks that the Server is currently tracking.)rrrrrrr7sz SharedMemoryServer.list_segmentsN) r4r6r7rWrr-rYrrXrrrrrrrrs rc@s<eZdZdZeZddZddZddZdd Z d d Z d S) raLike SyncManager but uses SharedMemoryServer instead of Server. It provides methods for creating and returning SharedMemory instances and for creating a list-like object (ShareableList) backed by shared memory. It also provides methods that create and return Proxy Objects that support synchronization across processes (i.e. multi-process-safe locks and semaphores). cOsNtjdkrddlm}|tj|f||t|j j dt dS)Nposixr )resource_trackerz created by pid ) rrrZensure_runningrr-rr{r3r4r)r,r@rrrrrr-Is   zSharedMemoryManager.__init__cCst|jjdtdS)Nz.__del__ by pid )rr{r3r4rr.rrrrUszSharedMemoryManager.__del__cCsh|jjtjkrP|jjtjkr&tdn*|jjtjkr>tdntd|jj||j |j |j |j S)z@Better than monkeypatching for now; merge into Server ultimatelyz"Already started SharedMemoryServerz!SharedMemoryManager has shut downr) rrrrrr rrKrrrrrr.rrrrYs    zSharedMemoryManager.get_serverc Csx|j|j|jd\}tjdd|d}zt|dd|jfWn.tk rh}z||W5d}~XYnXW5QRX|S)zoReturns a new SharedMemory instance with the specified size in bytes, to be tracked by the manager.rNT)rYsizer) rrrrrrDr BaseExceptionr)r,rrZsmsrrrrrfs z SharedMemoryManager.SharedMemoryc Csv|j|j|jdZ}t|}zt|dd|jjfWn0tk rf}z|j |W5d}~XYnXW5QRX|S)zReturns a new ShareableList instance populated with the values from the input sequence, to be tracked by the manager.rNr) rrrr ShareableListrDZshmrrr)r,r4rZslrrrrrrs   z!SharedMemoryManager.ShareableListN) r4r6r7r8rrr-rrrrrrrrr=s    )NNNT)T)S__all__rxrmrrZqueuerErrrrrr contextr r r rrrrrZ HAS_SHMEM ImportErrorrrZ view_typesr$r'Z view_typerTrrDr=rrLrTrVrWrrqrrZ XmlListenerZ XmlClientrhrrr rr$r*rr+r.r5r6r;r@rHrJrQrXrYrjrlrrpZ BasePoolProxyrqrryrtrnrzr{r|r}r~rrrrrrrrr s            c   w 4             %8