Mini Shell

Direktori : /lib64/python3.9/multiprocessing/__pycache__/
Upload File :
Current File : //lib64/python3.9/multiprocessing/__pycache__/managers.cpython-39.pyc

a

�DOgǸ�@sLgd�ZddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZddlmZdd	lmZdd
lmZddlmZzddlmZWney�d
ZYn0dZe�d�dd�Ze�eje�dd�dD�Zedeu�r8dd�ZeD]Ze�ee��q$Gdd�de �Z!difdd�Z"dd�Z#Gdd�de$�Z%d d!�Z&d"d#�Z'Gd$d%�d%e �Z(Gd&d'�d'e �Z)e
j*e
j+fe
j,e
j-fd(�Z.Gd)d*�d*e �Z/Gd+d,�d,e0�Z1Gd-d.�d.e �Z2d/d0�Z3ifd1d2�Z4dmd3d4�Z5Gd5d6�d6e �Z6Gd7d8�d8e �Z7dnd9d:�Z8Gd;d<�d<e2�Z9Gd=d>�d>e2�Z:Gd?d@�d@e:�Z;GdAdB�dBe2�Z<GdCdD�dDe2�Z=GdEdF�dFe2�Z>GdGdH�dHe2�Z?e4dIdJ�Z@GdKdL�dLe@�ZAe4dMdN�ZBdOdPieB_Ce4dQdR�ZDe4dSdT�ZEdUdUdUdPdPdV�eE_CGdWdS�dSeE�ZFGdXdY�dYe/�ZGeG�dZejH�eG�d[ejH�eG�d\ejIe<�eG�d]ejJe:�eG�d^ejKe:�eG�d_ejLe:�eG�d`ejMe:�eG�daejNe;�eG�dbejOe=�eG�dcejPeF�eG�ddeeA�eG�deeQeB�eG�d8e7e?�eG�d:e8eD�eG�d6e6e>�eGjdPe9d
df�eGjdUd
dg�e�rHGdhdi�di�ZRGdjdk�dke(�ZSGdld�de/�ZTdS)o)�BaseManager�SyncManager�	BaseProxy�Token�N)�getpid)�
format_exc�)�
connection)�	reduction�get_spawning_popen�ProcessError)�pool)�process)�util)�get_context)�
shared_memoryFT�SharedMemoryManagercCstj|j|��ffS�N)�array�typecode�tobytes)�a�r�0/usr/lib64/python3.9/multiprocessing/managers.py�reduce_array/srcCsg|]}tti|����qSr)�type�getattr��.0�namerrr�
<listcomp>3�r )�items�keys�valuescCstt|�ffSr)�list��objrrr�rebuild_as_list5sr(c@s4eZdZdZdZdd�Zdd�Zdd�Zd	d
�ZdS)rz3
    Type to uniquely identify a shared object
    ��typeid�address�idcCs||||_|_|_dSrr))�selfr*r+r,rrr�__init__DszToken.__init__cCs|j|j|jfSrr)�r-rrr�__getstate__GszToken.__getstate__cCs|\|_|_|_dSrr)�r-�staterrr�__setstate__JszToken.__setstate__cCsd|jj|j|j|jfS)Nz %s(typeid=%r, address=%r, id=%r))�	__class__�__name__r*r+r,r/rrr�__repr__Ms�zToken.__repr__N)	r5�
__module__�__qualname__�__doc__�	__slots__r.r0r3r6rrrrr>srrcCs8|�||||f�|��\}}|dkr*|St||��dS)zL
    Send a message to manager using connection `c` and return response
    �#RETURNN)�send�recv�convert_to_error)�cr,�
methodname�args�kwds�kind�resultrrr�dispatchUs
rEcCsd|dkr|S|dvrRt|t�s4td�||t|����|dkrHtd|�St|�Sntd�|��SdS)N�#ERROR)�
#TRACEBACK�#UNSERIALIZABLEz.Result {0!r} (kind '{1}') type is {2}, not strrHzUnserializable message: %s
zUnrecognized message type {!r})�
isinstance�str�	TypeError�formatr�RemoteError�
ValueError)rCrDrrrr>_s

��
r>c@seZdZdd�ZdS)rMcCsdt|jd�dS)NzM
---------------------------------------------------------------------------
rzK---------------------------------------------------------------------------)rJrAr/rrr�__str__oszRemoteError.__str__N)r5r7r8rOrrrrrMnsrMcCs2g}t|�D] }t||�}t|�r|�|�q|S)z4
    Return a list of names of methods of `obj`
    )�dirr�callable�append)r'�tempr�funcrrr�all_methodsvs
rUcCsdd�t|�D�S)zP
    Return a list of names of methods of `obj` which do not start with '_'
    cSsg|]}|ddkr|�qS)r�_rrrrrr �r!z"public_methods.<locals>.<listcomp>)rUr&rrr�public_methods�srWc@s�eZdZdZgd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zeee
d�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&S)'�ServerzM
    Server class which runs in a process controlled by a manager object
    )	�shutdown�create�accept_connection�get_methods�
debug_info�number_of_objects�dummy�incref�decrefcCsxt|t�std�|t|����||_t�|�|_t	|\}}||dd�|_
|j
j|_ddi|_i|_
i|_t��|_dS)Nz&Authkey {0!r} is type {1!s}, not bytes�)r+�backlog�0�Nr)rI�bytesrKrLr�registryr�AuthenticationString�authkey�listener_client�listenerr+�	id_to_obj�id_to_refcount�id_to_local_proxy_obj�	threading�Lock�mutex)r-rgr+ri�
serializer�Listener�Clientrrrr.�s
��

zServer.__init__c	Cs�t��|_|t��_z�tj|jd�}d|_|�	�z|j�
�sL|j�d�q4Wntt
fydYn0Wtjtjkr�t�d�tjt_tjt_t�d�n2tjtjkr�t�d�tjt_tjt_t�d�0dS)z(
        Run the server forever
        )�targetTrzresetting stdout, stderrrN)ro�Event�
stop_eventr�current_process�_manager_server�Thread�accepter�daemon�start�is_set�wait�KeyboardInterrupt�
SystemExit�sys�stdout�
__stdout__r�debug�
__stderr__�stderr�exit)r-r{rrr�
serve_forever�s*



�
zServer.serve_forevercCsLz|j��}Wnty$YqYn0tj|j|fd�}d|_|��qdS)N�rurAT)rk�accept�OSErrorrorz�handle_requestr|r})r-r?�trrrr{�s
zServer.acceptercCsNd}}}zTt�||j�t�||j�|��}|\}}}}||jvsTJd|��t||�}Wnty|dt�f}	YnB0z||g|�Ri|��}Wnty�dt�f}	Yn
0d|f}	z|�	|	�Wntt�y@}
zZz|�	dt�f�Wnt�yYn0t
�d|	�t
�d|�t
�d|
�WYd}
~
n
d}
~
00|��dS)z)
        Handle a new connection
        Nz%r unrecognizedrGr;zFailure to send message: %rz ... request was %r� ... exception was %r)
r	�deliver_challengeri�answer_challenger=�publicr�	Exceptionrr<r�info�close)r-r?�funcnamerD�request�ignorerArBrT�msg�errrr��s4"zServer.handle_requestcCs�t�dt��j�|j}|j}|j}|j�	��sΐz:d}}|�}|\}}}	}
z||\}}}WnPt
y�}
z8z|j|\}}}Wnt
y�|
�Yn0WYd}
~
n
d}
~
00||vr�td|t
|�|f��t||�}z||	i|
��}Wn.t�y}zd|f}WYd}~nXd}~00|�o,|�|d�}|�rb|�|||�\}}t||j|�}d||ff}nd|f}Wn�t�y�|du�r�dt�f}nRz2|j|}|||||g|	�Ri|
��}d|f}Wnt�y�dt�f}Yn0YnLt�yt�dt��j�t�d	�Ynt�y2dt�f}Yn0z4z||�Wn"t�yd|d
t�f�Yn0Wq$t�y�}zHt�dt��j�t�d|�t�d
|�|��t�d�WYd}~q$d}~00q$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=%rrF�#PROXYr;rGz$got EOF -- exiting thread serving %rrrHzexception in thread serving %rz ... message was %rr�r)rr�ro�current_threadrr=r<rlrwr~�KeyErrorrn�AttributeErrorrrr��getrZrr+r�fallback_mapping�EOFErrorr�r�r�r�)r-�connr=r<rlr@r'r��identrArB�exposed�	gettypeid�ke�function�resr�r�r*ZridentZrexposed�tokenZ
fallback_funcrDrrr�serve_client�s��� ��


�����zServer.serve_clientcCs|Srr�r-r�r�r'rrr�fallback_getvalue7szServer.fallback_getvaluecCst|�Sr�rJr�rrr�fallback_str:szServer.fallback_strcCst|�Sr)�reprr�rrr�
fallback_repr=szServer.fallback_repr)rOr6�	#GETVALUEcCsdSrr�r-r?rrrr_FszServer.dummyc
Cs�|j�vg}t|j���}|��|D]<}|dkr&|�d||j|t|j|d�dd�f�q&d�|�Wd�S1s�0YdS)zO
        Return some info --- useful to spot problems with refcounting
        rdz  %s:       refcount=%s
    %srN�K�
)	rqr%rmr#�sortrRrJrl�join)r-r?rDr#r�rrrr]Is
��zServer.debug_infocCs
t|j�S)z*
        Number of shared objects
        )�lenrmr�rrrr^YszServer.number_of_objectscCsVzDzt�d�|�d�Wnddl}|��Yn0W|j��n|j��0dS)z'
        Shutdown this process
        z!manager received shutdown message�r;NrN)rr�r<�	traceback�	print_excrw�set)r-r?r�rrrrY`s
zServer.shutdowncOs|j��|j|\}}}}|durD|s2t|�dkr:td��|d}	n||i|��}	|durbt|	�}|dur�t|t�s�td�|t	|����t
|�t
|�}dt|	�}
t�
d||
�|	t|�|f|j|
<|
|jvr�d|j|
<Wd�n1s�0Y|�||
�|
t|�fS)z>
        Create a new shared object and return its id
        Nrz4Without callable, must have one non-keyword argumentrz,Method_to_typeid {0!r}: type {1!s}, not dictz%xz&%r callable returned object with id %r)rqrgr�rNrWrI�dictrKrLrr%r,rr�r�rlrmr`�tuple)r-r?r*rArBrQr��method_to_typeid�	proxytyper'r�rrrrZms6�
�

��
(z
Server.createcCst|j|jd�S)zL
        Return the methods of the shared object indicated by token
        r)r�rlr,)r-r?r�rrrr\�szServer.get_methodscCs"|t��_|�d�|�|�dS)z=
        Spawn a new thread to serve this connection
        r�N)ror�rr<r�)r-r?rrrrr[�s

zServer.accept_connectioncCs�|j��z|j|d7<Wnjty�}zR||jvrpd|j|<|j||j|<|j|\}}}t�d|�n|�WYd}~n
d}~00Wd�n1s�0YdS)Nrz&Server re-enabled tracking & INCREF %r)rqrmr�rnrlrr�)r-r?r�r�r'r�r�rrrr`�s

�z
Server.increfcCs�||jvr$||jvr$t�d|�dS|j�d|j|dkrXtd�||j||j|���|j|d8<|j|dkr�|j|=Wd�n1s�0Y||jvr�d|j|<t�d|�|j�|j|=Wd�n1s�0YdS)NzServer DECREF skipping %rrz+Id {0!s} ({1!r}) has refcount {2:n}, not 1+r)NrNzdisposing of obj with id %r)rmrnrr�rq�AssertionErrorrLrl)r-r?r�rrrra�s*
�
��&

z
Server.decrefN)r5r7r8r9r�r.r�r{r�r�r�r�r�r�r_r]r^rYrZr\r[r`rarrrrrX�s.
"Q�
$rXc@seZdZdgZdZdZdZdS)�State�valuerr�N)r5r7r8r:�INITIAL�STARTED�SHUTDOWNrrrrr��sr�)�pickle�	xmlrpclibc@s�eZdZdZiZeZd"dd�Zdd�Zdd	�Z	d#dd�Z
ed$d
d��Zdd�Z
d%dd�Zdd�Zdd�Zdd�Zdd�Zedd��Zedd��Zed&d d!��ZdS)'rz!
    Base class for managers
    Nr�cCs\|durt��j}||_t�|�|_t�|_tj|j_	||_
t|\|_|_
|pTt�|_dSr)rrxri�_addressrh�_authkeyr��_stater�r��_serializerrjZ	_Listener�_Clientr�_ctx)r-r+rirr�ctxrrrr.�s

zBaseManager.__init__cCsf|jjtjkrP|jjtjkr&td��n*|jjtjkr>td��ntd�|jj���t|j	|j
|j|j�S)zX
        Return server object with serve_forever() method and address attribute
        �Already started server�Manager has shut down�Unknown state {!r})
r�r�r�r�r�rr�rLrX�	_registryr�r�r�r/rrr�
get_server�s

�
�zBaseManager.get_servercCs8t|j\}}||j|jd�}t|dd�tj|j_dS)z>
        Connect manager object to the server process
        �riNr_)	rjr�r�r�rEr�r�r�r�)r-rsrtr�rrr�connectszBaseManager.connectrc	Cs4|jjtjkrP|jjtjkr&td��n*|jjtjkr>td��ntd�|jj���|durht|�sht	d��t
jdd�\}}|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
        r�r�r�Nzinitializer must be a callableF)�duplexr��:css|]}t|�VqdSrr�)r�irrr�	<genexpr>(r!z$BaseManager.start.<locals>.<genexpr>�-r�rA�exitpriority)!r�r�r�r�r�rr�rLrQrKr	�Piper��Processr�_run_serverr�r�r�r��_processr��	_identityr5rr}r�r=r�Finalize�_finalize_managerr�rY)r-�initializer�initargs�reader�writerr�rrrr}s>

�
��



��zBaseManager.startc	Cs^t�tjtj�|dur ||�|�||||�}|�|j�|��t�d|j�|�	�dS)z@
        Create a server, report its address and run it
        Nzmanager serving at %r)
�signal�SIGINT�SIG_IGN�_Serverr<r+r�rr�r�)	�clsrgr+rirrr�r�r��serverrrrr�:szBaseManager._run_servercOsl|jjtjksJd��|j|j|jd�}z&t|dd|f||�\}}W|��n
|��0t	||j|�|fS)zP
        Create a new shared object; return the token and exposed tuple
        zserver not yet startedr�NrZ)
r�r�r�r�r�r�r�rEr�r)r-r*rArBr�r,r�rrr�_createQszBaseManager._createcCs*|jdur&|j�|�|j��s&d|_dS)zC
        Join the manager process (if it has been spawned)
        N)r�r��is_alive�r-�timeoutrrrr�]s

zBaseManager.joincCs8|j|j|jd�}zt|dd�W|��S|��0dS)zS
        Return some info about the servers shared objects and connections
        r�Nr]�r�r�r�rEr��r-r�rrr�_debug_infofs�zBaseManager._debug_infocCs8|j|j|jd�}zt|dd�W|��S|��0dS)z5
        Return the number of shared objects
        r�Nr^r�r�rrr�_number_of_objectsps�zBaseManager._number_of_objectscCsj|jjtjkr|��|jjtjkrf|jjtjkr<td��n*|jjtjkrTtd��ntd�|jj���|S)NzUnable to start serverr�r�)	r�r�r�r�r}r�rr�rLr/rrr�	__enter__zs

�zBaseManager.__enter__cCs|��dSr)rY�r-�exc_type�exc_val�exc_tbrrr�__exit__�szBaseManager.__exit__cCs�|��r�t�d�z4|||d�}zt|dd�W|��n
|��0WntyXYn0|jdd�|��r�t�d�t|d�r�t�d	�|��|jdd�|��r�t�d
�t	j
|_ztj
|=Wnty�Yn0dS)zQ
        Shutdown the manager process; will be registered as a finalizer
        z#sending shutdown message to managerr�NrYg�?)r�zmanager still alive�	terminatez'trying to `terminate()` manager processz#manager still alive after terminate)r�rr�rEr�r�r��hasattrr�r�r�r�r�_address_to_localr�)rr+rir2r�r�rrrr��s.




zBaseManager._finalize_managercCs|jSr)r�r/rrrr+�szBaseManager.addressTc
s�d|jvr|j��|_�dur"t�|p0t�dd�}|p@t�dd�}|r�t|���D]8\}}t|�tusrJd|��t|�tusRJd|��qR|||�f|j�<|r‡�fdd�}	�|	_	t
|�|	�dS)z9
        Register a typeid with the manager type
        r�N�	_exposed_�_method_to_typeid_z%r is not a stringcsft�d��|j�g|�Ri|��\}}�||j||j|d�}|j|j|jd�}t|dd|jf�|S)Nz)requesting creation of a shared %r object��managerrir�r�ra)	rr�r�r�r�r�r+rEr,)r-rArBr��exp�proxyr��r�r*rrrS�s�z"BaseManager.register.<locals>.temp)�__dict__r��copy�	AutoProxyrr%r"rrJr5�setattr)
r�r*rQr�r�r��
create_method�keyr�rSrrr�register�s$

��

zBaseManager.register)NNr�N)Nr)Nr)N)NNNNT)r5r7r8r9r�rXr�r.r�r�r}�classmethodr�r�r�r�r�r�r��staticmethodr��propertyr+r
rrrrr�s4�
	
+�
	




�rc@seZdZdd�Zdd�ZdS)�ProcessLocalSetcCst�|dd��dS)NcSs|��Sr)�clearr&rrr�<lambda>�r!z*ProcessLocalSet.__init__.<locals>.<lambda>)r�register_after_forkr/rrrr.�szProcessLocalSet.__init__cCst|�dfSre)rr/rrr�
__reduce__�szProcessLocalSet.__reduce__N)r5r7r8r.rrrrrr�src@s�eZdZdZiZe��Zddd�Zdd�Z	d	ifd
d�Z
dd
�Zdd�Ze
dd��Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)rz.
    A base for proxies of shared objects
    NTFc	Cs�tj�Btj�|jd�}|dur:t��t�f}|tj|j<Wd�n1sN0Y|d|_|d|_	||_
|j
j|_||_
||_t|d|_||_|dur�t�|�|_n"|j
dur�|j
j|_nt��j|_|r�|��t�|tj�dS)Nrr)r�_mutexr�r�r+r�ForkAwareLocalr�_tls�_idset�_tokenr,�_id�_managerr�rjr��_owned_by_managerrrhr�rxri�_increfr�_after_fork)	r-r�rrrrir�r`�
manager_ownedZ	tls_idsetrrrr.�s**



zBaseProxy.__init__cCsdt�d�t��j}t��jdkr4|dt��j7}|j|jj	|j
d�}t|dd|f�||j_
dS)Nzmaking connection to manager�
MainThread�|r�r[)rr�rrxrror�r�rr+r�rErr	)r-rr�rrr�_connects

zBaseProxy._connectrcCs�z|jj}Wn4ty@t�dt��j�|��|jj}Yn0|�	|j
|||f�|��\}}|dkrn|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;r����rr�Nra)rr	r�rr�ror�rr#r<rr=rr�r*rr+r�r�r�rEr,r>)r-r@rArBr�rCrDr�r�r�rrrr�_callmethods0�

�zBaseProxy._callmethodcCs
|�d�S)z9
        Get a copy of the value of the referent
        r��r%r/rrr�	_getvalue;szBaseProxy._getvaluec	Cs�|jrt�d|jj�dS|j|jj|jd�}t|dd|j	f�t�d|jj�|j
�|j	�|joj|jj
}tj|tj|j|j||j|j
|jfdd�|_dS)Nz%owned_by_manager skipped INCREF of %rr�r`z	INCREF %r�
r�)rrr�rr,r�r+r�rErr�addrr�r�r�_decrefr�_close)r-r�r2rrrrAs
��zBaseProxy._increfc
Cs�|�|j�|dus |jtjkr�z2t�d|j�||j|d�}t|dd|jf�Wq�t	y�}zt�d|�WYd}~q�d}~00nt�d|j�|s�t
|d�r�t�dt��j
�|j��|`dS)Nz	DECREF %rr�raz... decref failed %sz%DECREF %r -- manager already shutdownr	z-thread %r has no more proxies so closing conn)�discardr,r�r�r�rr�r+rEr�r�ror�rr	r�)r�rir2ZtlsZidsetr�r�r�rrrr*Us$�
zBaseProxy._decrefc
CsJd|_z|��Wn2tyD}zt�d|�WYd}~n
d}~00dS)Nzincref failed: %s)rrr�rr�)r-r�rrrrns
zBaseProxy._after_forkcCs^i}t�dur|j|d<t|dd�rB|j|d<tt|j|j|ffStt|�|j|j|ffSdS)Nri�_isautoFr�)	rr�rr�RebuildProxyr	rr�r�r-rBrrrrvs


��zBaseProxy.__reduce__cCs|��Sr)r')r-�memorrr�__deepcopy__�szBaseProxy.__deepcopy__cCsdt|�j|jjt|�fS)Nz<%s object, typeid %r at %#x>)rr5rr*r,r/rrrr6�s�zBaseProxy.__repr__cCs8z|�d�WSty2t|�dd�dYS0dS)zV
        Return representation of the referent (or a fall-back if that fails)
        r6Nr$z; '__str__()' failed>)r%r�r�r/rrrrO�szBaseProxy.__str__)NNNTF)r5r7r8r9r�r�ForkAwareThreadLockrr.r#r%r'rrr*rrr1r6rOrrrrr�s"�
)	

rcCs�tt��dd�}|rT|j|jkrTt�d|�d|d<|j|jvrT|j|j|j|j<|�	dd�optt��dd�}|||fd|i|��S)	z5
    Function used for unpickling proxy objects.
    ryNz*Rebuild a proxy owned by manager, token=%rTr r`Z_inheritingF)
rrrxr+rr�r,rnrl�pop)rTr�rrrBr�r`rrrr.�s
�
�r.cCsnt|�}z|||fWSty(Yn0i}|D]}td||f|�q2t|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))r�r��execrrr)rr��_cacheZdic�meth�	ProxyTyperrr�
MakeProxyType�s ��r8cCs�t|d}|durJ||j|d�}zt|dd|f�}W|��n
|��0|dur`|dur`|j}|durrt��j}td|j	|�}	|	||||||d�}
d|
_
|
S)z*
    Return an auto-proxy for `token`
    rNr�r\z
AutoProxy[%s])rrir`r T)rjr+rEr�r�rrxrir8r*r-)r�rrrrir�r`r r�r�r7rrrrr	�s 

�r	c@seZdZdd�Zdd�ZdS)�	NamespacecKs|j�|�dSr)r�updater/rrrr.�szNamespace.__init__cCsZt|j���}g}|D]$\}}|�d�s|�d||f�q|��d|jjd�|�fS)NrVz%s=%rz%s(%s)z, )	r%rr"�
startswithrRr�r4r5r�)r-r"rSrr�rrrr6�s
zNamespace.__repr__N)r5r7r8r.r6rrrrr9�sr9c@s8eZdZddd�Zdd�Zdd�Zdd	�Zeee�Zd
S)�ValueTcCs||_||_dSr)�	_typecode�_value)r-rr��lockrrrr.�szValue.__init__cCs|jSr�r>r/rrrr��sz	Value.getcCs
||_dSrr@�r-r�rrrr��sz	Value.setcCsdt|�j|j|jfS)Nz
%s(%r, %r))rr5r=r>r/rrrr6�szValue.__repr__N)T)	r5r7r8r.r�r�r6rr�rrrrr<�s

r<cCst�||�Sr)r)r�sequencer?rrr�Array�srCc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�
IteratorProxy)�__next__r<�throwr�cCs|Srrr/rrr�__iter__szIteratorProxy.__iter__cGs|�d|�S)NrEr&�r-rArrrrEszIteratorProxy.__next__cGs|�d|�S)Nr<r&rHrrrr<szIteratorProxy.sendcGs|�d|�S)NrFr&rHrrrrFszIteratorProxy.throwcGs|�d|�S)Nr�r&rHrrrr�szIteratorProxy.closeN)	r5r7r8rrGrEr<rFr�rrrrrD�srDc@s2eZdZdZddd�Zdd�Zdd	�Zd
d�ZdS)
�
AcquirerProxy)�acquire�releaseTNcCs"|dur|fn||f}|�d|�S�NrJr&)r-�blockingr�rArrrrJszAcquirerProxy.acquirecCs
|�d�S�NrKr&r/rrrrKszAcquirerProxy.releasecCs
|�d�SrLr&r/rrrr�szAcquirerProxy.__enter__cCs
|�d�SrNr&r�rrrr�szAcquirerProxy.__exit__)TN)r5r7r8rrJrKr�r�rrrrrIs

rIc@s6eZdZdZddd�Zd
dd�Zdd	�Zdd
d�ZdS)�ConditionProxy)rJrKr�notify�
notify_allNcCs|�d|f�S�Nrr&r�rrrrszConditionProxy.waitrcCs|�d|f�S)NrPr&)r-�nrrrrPszConditionProxy.notifycCs
|�d�S)NrQr&r/rrrrQszConditionProxy.notify_allcCsd|�}|r|S|dur$t��|}nd}d}|s`|durN|t��}|dkrNq`|�|�|�}q,|S)Nr)�time�	monotonicr)r-�	predicater�rD�endtime�waittimerrr�wait_for!s
zConditionProxy.wait_for)N)r)N)r5r7r8rrrPrQrYrrrrrOs


rOc@s2eZdZdZdd�Zdd�Zdd�Zdd	d
�ZdS)�
EventProxy)r~r�rrcCs
|�d�S)Nr~r&r/rrrr~6szEventProxy.is_setcCs
|�d�S�Nr�r&r/rrrr�8szEventProxy.setcCs
|�d�S)Nrr&r/rrrr:szEventProxy.clearNcCs|�d|f�SrRr&r�rrrr<szEventProxy.wait)N)r5r7r8rr~r�rrrrrrrZ4s
rZc@sNeZdZdZddd�Zdd�Zdd�Zed	d
��Zedd��Z	ed
d��Z
dS)�BarrierProxy)�__getattribute__r�abort�resetNcCs|�d|f�SrRr&r�rrrrBszBarrierProxy.waitcCs
|�d�S)Nr^r&r/rrrr^DszBarrierProxy.abortcCs
|�d�S)Nr_r&r/rrrr_FszBarrierProxy.resetcCs|�dd�S)Nr])�partiesr&r/rrrr`HszBarrierProxy.partiescCs|�dd�S)Nr])�	n_waitingr&r/rrrraKszBarrierProxy.n_waitingcCs|�dd�S)Nr])�brokenr&r/rrrrbNszBarrierProxy.broken)N)r5r7r8rrr^r_rr`rarbrrrrr\@s


r\c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�NamespaceProxy)r]�__setattr__�__delattr__cCs0|ddkrt�||�St�|d�}|d|f�S)NrrVr%r])�objectr]�r-r�
callmethodrrr�__getattr__UszNamespaceProxy.__getattr__cCs4|ddkrt�|||�St�|d�}|d||f�S)NrrVr%rd)rfrdr])r-rr�rhrrrrdZszNamespaceProxy.__setattr__cCs0|ddkrt�||�St�|d�}|d|f�S)NrrVr%re)rfrer]rgrrrre_szNamespaceProxy.__delattr__N)r5r7r8rrirdrerrrrrcSsrcc@s4eZdZdZdd�Zdd�Zeee�Zee	j
�ZdS)�
ValueProxy)r�r�cCs
|�d�S)Nr�r&r/rrrr�hszValueProxy.getcCs|�d|f�Sr[r&rArrrr�jszValueProxy.setN)r5r7r8rr�r�rr�r�types�GenericAlias�__class_getitem__rrrrrjfs

rj�
BaseListProxy)�__add__�__contains__�__delitem__�__getitem__�__len__�__mul__�__reversed__�__rmul__�__setitem__rR�count�extend�index�insertr3�remove�reverser��__imul__c@seZdZdd�Zdd�ZdS)�	ListProxycCs|�d|f�|S)Nryr&rArrr�__iadd__xszListProxy.__iadd__cCs|�d|f�|S)Nr~r&rArrrr~{szListProxy.__imul__N)r5r7r8r�r~rrrrrwsr�	DictProxy)rprqrrrGrsrwrrr�r"r#r3�popitem�
setdefaultr:r$rG�Iterator�
ArrayProxy)rsrrrw�	PoolProxy)Zapply�apply_asyncr��imap�imap_unorderedr��map�	map_async�starmap�
starmap_asyncr�ZAsyncResult)r�r�r�r�r�c@seZdZdd�Zdd�ZdS)r�cCs|Srrr/rrrr��szPoolProxy.__enter__cCs|��dSr)r�r�rrrr��szPoolProxy.__exit__N)r5r7r8r�r�rrrrr��sc@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)r5r7r8r9rrrrr�sr�Queue�
JoinableQueuervrp�RLock�	Semaphore�BoundedSemaphore�	Condition�Barrier�Poolr%r�)r�r)rc@sLeZdZdZgfdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�_SharedMemoryTrackerz+Manages one or more shared memory segments.cCs||_||_dSr�Zshared_memory_context_name�
segment_names)r-rr�rrrr.�sz_SharedMemoryTracker.__init__cCs(t�d|�dt����|j�|�dS)z6Adds the supplied shared memory block name to tracker.zRegister segment � in pid N)rr�rr�rR�r-�segment_namerrr�register_segment�sz%_SharedMemoryTracker.register_segmentcCsBt�d|�dt����|j�|�t�|�}|��|��dS)z�Calls unlink() on the shared memory block with the supplied name
            and removes it from the list of blocks being tracked.zDestroy segment r�N)	rr�rr�r|r�SharedMemoryr��unlink)r-r�Zsegmentrrr�destroy_segment�s

z$_SharedMemoryTracker.destroy_segmentcCs"|jdd�D]}|�|�qdS)z<Calls destroy_segment() on all tracked shared memory blocks.N)r�r�r�rrrr��sz_SharedMemoryTracker.unlinkcCs(t�d|jj�dt����|��dS)NzCall z.__del__ in )rr�r4r5rr�r/rrr�__del__�sz_SharedMemoryTracker.__del__cCs|j|jfSrr�r/rrrr0�sz!_SharedMemoryTracker.__getstate__cCs|j|�dSr)r.r1rrrr3�sz!_SharedMemoryTracker.__setstate__N)r5r7r8r9r.r�r�r�r�r0r3rrrrr��s	r�c@sJeZdZejgd�Zdd�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dS)�SharedMemoryServer)�
track_segment�release_segment�
list_segmentscOs`tj|g|�Ri|��|j}t|t�r2t�|�}td|�dt����|_	t
�dt����dS)NZshm_rVz"SharedMemoryServer started by pid )rXr.r+rIrf�os�fsdecoder�r�shared_memory_contextrr�)r-rA�kwargsr+rrrr.�s

�zSharedMemoryServer.__init__cOs:t|j|dd�r|j|d<tj|||g|�Ri|��S)z�Create a new distributed-shared object (not backed by a shared
            memory block) and return its id to be used in a Proxy Object.r$Z_shared_memory_proxyr�)r�rgr�rXrZ)r-r?r*rAr�rrrrZ�s
zSharedMemoryServer.createcCs|j��t�||�S)zACall unlink() on all tracked shared memory, terminate the Server.)r�r�rXrYr�rrrrYs
zSharedMemoryServer.shutdowncCs|j�|�dS)z?Adds the supplied shared memory block name to Server's tracker.N)r�r��r-r?r�rrrr�sz SharedMemoryServer.track_segmentcCs|j�|�dS)z�Calls unlink() on the shared memory block with the supplied name
            and removes it from the tracker instance inside the Server.N)r�r�r�rrrr�sz"SharedMemoryServer.release_segmentcCs|jjS)zbReturns a list of names of shared memory blocks that the Server
            is currently tracking.)r�r�r�rrrr�sz SharedMemoryServer.list_segmentsN)r5r7r8rXr�r.rZrYr�r�r�rrrrr��s�

r�c@s<eZdZdZeZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dS)
ra�Like 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).
        cOsTtjdkrddlm}|��tj|g|�Ri|��t�|j	j
�dt����dS)N�posixr)�resource_trackerz created by pid )r�r�r�Zensure_runningrr.rr�r4r5r)r-rAr�r�rrrr.'s

zSharedMemoryManager.__init__cCst�|jj�dt����dS)Nz.__del__ by pid )rr�r4r5rr/rrrr�3szSharedMemoryManager.__del__cCsh|jjtjkrP|jjtjkr&td��n*|jjtjkr>td��ntd�|jj���|�|j	|j
|j|j�S)z@Better than monkeypatching for now; merge into Server ultimatelyz"Already started SharedMemoryServerz!SharedMemoryManager has shut downr�)
r�r�r�r�r�rr�rLr�r�r�r�r�r/rrrr�7s

��zSharedMemoryManager.get_servercCs�|j|j|jd��h}tjdd|d�}zt|dd|jf�Wn0tyj}z|��|�WYd}~n
d}~00Wd�n1s�0Y|S)zoReturns a new SharedMemory instance with the specified size in
            bytes, to be tracked by the manager.r�NT)rZ�sizer�)	r�r�r�rr�rEr�
BaseExceptionr�)r-r�r�Zsmsr�rrrr�Ds8z SharedMemoryManager.SharedMemorycCs�|j|j|jd��f}t�|�}zt|dd|jjf�Wn2tyh}z|j�	�|�WYd}~n
d}~00Wd�n1s~0Y|S)z�Returns a new ShareableList instance populated with the values
            from the input sequence, to be tracked by the manager.r�Nr�)
r�r�r�r�
ShareableListrEZshmrr�r�)r-rBr��slr�rrrr�Ps

8z!SharedMemoryManager.ShareableListN)r5r7r8r9r�r�r.r�r�r�r�rrrrrs	
)NNNTF)T)U�__all__r�ror�r�queuerTrkr�rr�rr�r	�contextr
rrr
rrrr�ImportErrorZ	HAS_SHMEMrRrr
Z
view_typesr%r(Z	view_typerfrrEr>r�rMrUrWrXr�rsrt�XmlListener�	XmlClientrjrr�rrr.r8r	r9r<rCrDrIrOrZr\rcrjrnrr�rr�Z
BasePoolProxyr�rr�rvrpr�r�r�r�r�r�r�r�r�rrrrr�<module>s�



H

�	w
4�



	
�

�

�%-

Zerion Mini Shell 1.0