AlkantarClanX12

Your IP : 3.149.25.117


Current Path : /opt/alt/python310/lib64/python3.10/multiprocessing/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/multiprocessing/__pycache__/managers.cpython-310.opt-1.pyc

o

6��f���@sPgd�ZddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZddlmZdd	lmZdd
lmZddlmZzddlmZWneykd
ZYnwdZe�d�dd�Ze�eje�dd�dD�Zedeur�dd�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�Z4		
dmd3d4�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�r&Gdhdi�di�ZRGdjdk�dke(�ZSGdld�de/�ZTdSdS)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�?/opt/alt/python310/lib64/python3.10/multiprocessing/managers.py�reduce_array/�rcCsg|]
}tti|����qSr)�type�getattr��.0�namerrr�
<listcomp>3�r!)�items�keys�valuescCstt|�ffSr)�list��objrrr�rebuild_as_list5�r)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__G�zToken.__getstate__cCs|\|_|_|_dSrr+�r/�staterrr�__setstate__JrzToken.__setstate__cCsd|jj|j|j|jfS)Nz %s(typeid=%r, address=%r, id=%r))�	__class__�__name__r,r-r.r1rrr�__repr__Ms�zToken.__repr__N)	r8�
__module__�__qualname__�__doc__�	__slots__r0r2r6r9rrrrr>srrcCs4|�||||f�|��\}}|dkr|St||��)zL
    Send a message to manager using connection `c` and return response
    �#RETURN)�send�recv�convert_to_error)�cr.�
methodname�args�kwds�kind�resultrrr�dispatchUs

rHcCs^|dkr|S|dvr(t|t�std�||t|����|dkr$td|�St|�Std�|��S)N�#ERROR)�
#TRACEBACK�#UNSERIALIZABLEz.Result {0!r} (kind '{1}') type is {2}, not strrKzUnserializable message: %s
zUnrecognized message type {!r})�
isinstance�str�	TypeError�formatr�RemoteError�
ValueError)rFrGrrrrA_s

��rAc@seZdZdd�ZdS)rPcCsdt|jd�dS)NzM
---------------------------------------------------------------------------
rzK---------------------------------------------------------------------------)rMrDr1rrr�__str__oszRemoteError.__str__N)r8r:r;rRrrrrrPnsrPcCs2g}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

�rXcCsdd�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>)rXr'rrr�public_methods�srZc@s�eZdZdZgd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
ee
ed�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�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-Zbacklog�0�Nr)rL�bytesrNrOr�registryr�AuthenticationString�authkey�listener_client�listenerr-�	id_to_obj�id_to_refcount�id_to_local_proxy_obj�	threading�Lock�mutex)r/rir-rk�
serializer�Listener�Clientrrrr0�s
��

zServer.__init__c	Cs�t��|_|t��_zGtj|jd�}d|_|�	�z|j�
�s*|j�d�|j�
�rWntt
fy6YnwWtjtjkrKt�d�tjt_tjt_t�d�dStjtjkret�d�tjt_tjt_t�d�w)z(
        Run the server forever
        )�targetTrzresetting stdout, stderrrN)rq�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�s2



����
�
zServer.serve_forevercCsF	z|j��}Wn	tyYqwtj|j|fd�}d|_|��q)NT�rwrD)rmZaccept�OSErrorrqr|�handle_requestr~r)r/rB�trrrr}�s��zServer.acceptercCs$d}zt�||j�t�||j�|��}|\}}}}t||�}Wnty/dt�f}Yn!wz
||g|�Ri|��}	WntyKdt�f}Ynwd|	f}z|�|�WdSty�}
z-z
|�dt�f�Wn	tysYnwt	�
d|�t	�
d|�t	�
d|
�WYd}
~
dSd}
~
ww)NrJr>zFailure to send message: %rz ... request was %r� ... exception was %r)r	Zdeliver_challengerkZanswer_challenger@r�	Exceptionrr?r�info)r/rB�request�ignore�funcnamerDrErW�msgrG�errr�_handle_request�s:�����zServer._handle_requestcCsJzz|�|�Wn	tyYnwW|��dSW|��dS|��w)z)
        Handle a new connection
        N)r�r��close�r/�connrrrr��s���zServer.handle_requestcCs�t�dt��j�|j}|j}|j}|j�	��sdz�d}}|�}|\}}}	}
z	||\}}}Wn&t
yU}
zz
|j|\}}}Wn	t
yJ|
�wWYd}
~
nd}
~
ww||vretd|t
|�|f��t||�}z	||	i|
��}Wnty�}z
d|f}WYd}~n*d}~ww|o�|�|d�}|r�|�|||�\}}t||j|�}d||ff}nd|f}Wn`ty�|dur�dt�f}n(z|j|}|||||g|	�Ri|
��}d|f}Wnty�dt�f}YnwYn&t�yt�dt��j�t�d	�Ynt�ydt�f}Ynwzz||�Wnt�y)|d
t�f�YnwWn1t�y\}z$t�dt��j�t�d|�t�d
|�|��t�d�WYd}~nd}~ww|j�	�rdSdS)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=%rrI�#PROXYr>rJz$got EOF -- exiting thread serving %rrrKzexception in thread serving %rz ... message was %rr�r)rr�rq�current_threadr r@r?rnryr��KeyErrorrp�AttributeErrorrrr��getr]rr-r�fallback_mapping�EOFErrorr�r�r�r�)r/r�r@r?rnrCr(r��identrDrE�exposed�	gettypeid�keZfunction�resr�r�r,ZridentZrexposed�tokenZ
fallback_funcrGrrr�serve_client�s���������
���
�������������zServer.serve_clientcCs|Srr�r/r�r�r(rrr�fallback_getvalue?�zServer.fallback_getvaluecC�t|�Sr�rMr�rrr�fallback_strB�zServer.fallback_strcCr�r)�reprr�rrr�
fallback_reprEr�zServer.fallback_repr)rRr9�	#GETVALUEcCsdSrr�r/rBrrrrbNr�zServer.dummyc
Cs�|j�;g}t|j���}|��|D]}|dkr1|�d||j|t|j|d�dd�f�qd�|�Wd�S1sAwYdS)zO
        Return some info --- useful to spot problems with refcounting
        rfz  %s:       refcount=%s
    %srN�K�
)	rsr&ror$�sortrUrMrn�join)r/rBrGr$r�rrrr`Qs
���$�zServer.debug_infocCs
t|j�S)z*
        Number of shared objects
        )�lenror�rrrraas
zServer.number_of_objectscCs`z)zt�d�|�d�Wnddl}|��YW|j��dSW|j��dS|j��w)z'
        Shutdown this process
        z!manager received shutdown message�r>NrN)rr�r?�	traceback�	print_excry�set)r/rBr�rrrr\hs
�zServer.shutdowncOs|j�q|j|\}}}}|dur"|st|�dkrtd��|d}	n||i|��}	|dur1t|	�}|durLt|t�sDtd�|t	|����t
|�t
|�}dt|	�}
t�
d||
�|	t|�|f|j|
<|
|jvrmd|j|
<Wd�n1swwY|�||
�|
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)rsrir�rQrZrL�dictrNrOrr&r.rr�r�rnrorc�tuple)r/rBr,rDrErTr��method_to_typeid�	proxytyper(r�rrrr]us:
��

��

��z
Server.createcCst|j|jd�S)zL
        Return the methods of the shared object indicated by token
        r)r�rnr.)r/rBr�rrrr_�szServer.get_methodscCs"|t��_|�d�|�|�dS)z=
        Spawn a new thread to serve this connection
        r�N)rqr�r r?r�)r/rBr rrrr^�s

zServer.accept_connectioncCs�|j�Rz|j|d7<Wn5tyD}z)||jvr8d|j|<|j||j|<|j|\}}}t�d|�n|�WYd}~n
d}~wwWd�dSWd�dS1sXwYdS)Nrz&Server re-enabled tracking & INCREF %r)rsror�rprnrr�)r/rBr�r�r(r�r�rrrrc�s$

������
"�z
Server.increfcCs�||jvr||jvrt�d|�dS|j�2|j|dkr,td�||j||j|���|j|d8<|j|dkr@|j|=Wd�n1sJwY||jvryd|j|<t�d|�|j�
|j|=Wd�dS1srwYdSdS)NzServer DECREF skipping %rrz+Id {0!s} ({1!r}) has refcount {2:n}, not 1+r)NrNzdisposing of obj with id %r)rorprr�rs�AssertionErrorrOrn)r/rBr�rrrrd�s0


����



"��z
Server.decrefN)r8r:r;r<�publicr0r�r}r�r�r�r�r�r�r�rbr`rar\r]r_r^rcrdrrrrr[�s2
Q�
$r[c@seZdZdgZdZdZdZdS)�State�valuerr�N)r8r:r;r=�INITIAL�STARTED�SHUTDOWNrrrrr��s
r�)�pickleZ	xmlrpclibc@s�eZdZdZiZeZ		d"dd�Zdd�Zdd	�Z	d#dd�Z
e	
d#d
d��Zdd�Z
d$dd�Zdd�Zdd�Zdd�Zdd�Zedd��Zedd��Ze		d%d d!��ZdS)&rz!
    Base class for managers
    Nr�cCs\|dur	t��j}||_t�|�|_t�|_tj|j_	||_
t|\|_|_
|p*t�|_dSr)rrzrk�_addressrj�_authkeyr��_stater�r��_serializerrlZ	_Listener�_Clientr�_ctx)r/r-rkrt�ctxrrrr0�s

zBaseManager.__init__cCsb|jjtjkr&|jjtjkrtd��|jjtjkrtd��td�|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�rOr[�	_registryr�r�r�r1rrr�
get_server�s�
�zBaseManager.get_servercCs8t|j\}}||j|jd�}t|dd�tj|j_dS)z>
        Connect manager object to the server process
        �rkNrb)	rlr�r�r�rHr�r�r�r�)r/rurvr�rrr�connectszBaseManager.connectrc	Cs0|jjtjkr&|jjtjkrtd��|jjtjkrtd��td�|jj���|dur2t|�s2t	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)Zduplexr��:css�|]}t|�VqdSrr�)r�irrr�	<genexpr>0s�z$BaseManager.start.<locals>.<genexpr>�-r�rDZexitpriority)!r�r�r�r�r�rr�rOrTrNr	ZPiper�ZProcessr�_run_serverr�r�r�r��_processr�Z	_identityr8r rr�r@r�Finalize�_finalize_managerr�r\)r/�initializer�initargs�reader�writerr�rrrrs>�
��



��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�)	�clsrir-rkrtr�r�r��serverrrrr�BszBaseManager._run_servercOsV|j|j|jd�}zt|dd|f||�\}}W|��n|��wt||j|�|fS)zP
        Create a new shared object; return the token and exposed tuple
        r�Nr])r�r�r�rHr�r)r/r,rDrEr�r.r�rrr�_createYs
zBaseManager._createcCs2|jdur|j�|�|j��sd|_dSdSdS)zC
        Join the manager process (if it has been spawned)
        N)r�r��is_alive�r/�timeoutrrrr�es


�zBaseManager.joincC�4|j|j|jd�}zt|dd�W|��S|��w)zS
        Return some info about the servers shared objects and connections
        r�Nr`�r�r�r�rHr�r�rrr�_debug_infon�zBaseManager._debug_infocCr�)z5
        Return the number of shared objects
        r�Nrar�r�rrr�_number_of_objectsxr�zBaseManager._number_of_objectscCsf|jjtjkr|��|jjtjkr1|jjtjkrtd��|jjtjkr(td��td�|jj���|S)NzUnable to start serverr�r�)	r�r�r�r�rr�rr�rOr1rrr�	__enter__�s�zBaseManager.__enter__cC�|��dSr)r\�r/�exc_typeZexc_valZexc_tbrrr�__exit__��zBaseManager.__exit__cCs�|��rYt�d�z|||d�}zt|dd�W|��n|��wWn	ty,Ynw|jdd�|��rYt�d�t|d�rYt�d	�|��|jdd�|��rYt�d
�t	j
|_ztj
|=WdStynYdSw)zQ
        Shutdown the manager process; will be registered as a finalizer
        z#sending shutdown message to managerr�Nr\g�?)r�zmanager still alive�	terminatez'trying to `terminate()` manager processz#manager still alive after terminate)r�rr�rHr�r�r��hasattrr�r�r�r�r�_address_to_localr�)rr-rkr5r�r�rrrr��s2
�



�zBaseManager._finalize_managercC�|jSr)r�r1rrrr-�szBaseManager.addressTc
s�d|jvr|j��|_�durt�|pt�dd�}|p t�dd�}|r.t|���D]\}}q)|||�f|j�<|rK��fdd�}	�|	_t|�|	�dSdS)z9
        Register a typeid with the manager type
        r�N�	_exposed_�_method_to_typeid_csft�d��|j�g|�Ri|��\}}�||j||j|d�}|j|j|jd�}t|dd|jf�|S)Nz)requesting creation of a shared %r object��managerrkr�r�rd)	rr�r�r�r�r�r-rHr.)r/rDrEr�Zexp�proxyr��r�r,rrrV�s�z"BaseManager.register.<locals>.temp)	�__dict__r��copy�	AutoProxyrr&r#r8�setattr)
r�r,rTr�r�r��
create_method�keyr�rVrrr�register�s"

�
�
�zBaseManager.register)NNr�Nrgr)NNNNT)r8r:r;r<r�r[r�r0r�r�r�classmethodr�r�r�r�r�r�r��staticmethodr��propertyr-rrrrrr�s6
�
	+�
	




�rc@�eZdZdd�Zdd�ZdS)�ProcessLocalSetcCst�|dd��dS)NcS�|��Sr)�clearr'rrr�<lambda>�sz*ProcessLocalSet.__init__.<locals>.<lambda>)r�register_after_forkr1rrrr0�rzProcessLocalSet.__init__cCst|�dfSrg)rr1rrr�
__reduce__�r�zProcessLocalSet.__reduce__N)r8r:r;r0rrrrrr��rc@s�eZdZdZiZe��Z		ddd�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�!tj�|jd�}|durt��t�f}|tj|j<Wd�n1s'wY|d|_|d|_	||_
|j
j|_||_
||_t|d|_||_|durYt�|�|_n|j
durd|j
j|_nt��j|_|rp|��t�|tj�dS)Nrr)r�_mutexr�r�r-rZForkAwareLocalr�_tls�_idset�_tokenr.�_id�_managerr�rlr��_owned_by_managerrrjr�rzrk�_increfr�_after_fork)	r/r�rtrrkr�rc�
manager_ownedZ	tls_idsetrrrr0�s.��



zBaseProxy.__init__cCsdt�d�t��j}t��jdkr|dt��j7}|j|jj	|j
d�}t|dd|f�||j_
dS)Nzmaking connection to managerZ
MainThread�|r�r^)rr�rrzr rqr�r�rr-r�rHrr	)r/r r�rrr�_connects

zBaseProxy._connectrcCs�z|jj}Wnty t�dt��j�|��|jj}Ynw|�	|j
|||f�|��\}}|dkr7|S|dkrm|\}}|jj
|jd}	|jj|_|	||j|j|j|d�}
|j|j|jd�}t|dd|jf�|
St||��)	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�Nrd)rr	r�rr�rqr�r r"r?rr@rr�r,rr-r�r�r�rHr.rA)r/rCrDrEr�rFrGr�r�r�rrrr�_callmethod%s2��

�
zBaseProxy._callmethodcC�
|�d�S)z9
        Get a copy of the value of the referent
        r��r$r1rrr�	_getvalueCs
zBaseProxy._getvaluec	Cs�|jr
t�d|jj�dS|j|jj|jd�}t|dd|j	f�t�d|jj�|j
�|j	�|jo5|jj
}tj|tj|j|j||j|j
|jfdd�|_dS)Nz%owned_by_manager skipped INCREF of %rr�rcz	INCREF %r�
r�)rrr�rr.r�r-r�rHrr�addrr�r�r�_decrefrZ_close)r/r�r5rrrrIs
��zBaseProxy._increfc
Cs�|�|j�|dus|jtjkrBzt�d|j�||j|d�}t|dd|jf�Wnt	yA}zt�d|�WYd}~nd}~wwt�d|j�|sbt
|d�rdt�dt��j
�|j��|`dSdSdS)Nz	DECREF %rr�rdz... decref failed %sz%DECREF %r -- manager already shutdownr	z-thread %r has no more proxies so closing conn)�discardr.r�r�r�rr�r-rHr�r�rqr�r r	r�)r�rkr5ZtlsZidsetr�r�r�rrrr*]s$���
�zBaseProxy._decrefc
CsJd|_z|��WdSty$}zt�d|�WYd}~dSd}~ww)Nzincref failed: %s)rrr�rr�)r/r�rrrrvs��zBaseProxy._after_forkcCsZi}t�dur|j|d<t|dd�r!|j|d<tt|j|j|ffStt|�|j|j|ffS)Nrk�_isautoFr�)	rr�rr��RebuildProxyrrr�r�r/rErrrr~s


��zBaseProxy.__reduce__cCrr)r')r/Zmemorrr�__deepcopy__�r�zBaseProxy.__deepcopy__cCsdt|�j|jjt|�fS)Nz<%s object, typeid %r at %#x>)rr8rr,r.r1rrrr9�s�zBaseProxy.__repr__cCs4z|�d�WStyt|�dd�dYSw)zV
        Return representation of the referent (or a fall-back if that fails)
        r9Nr#z; '__str__()' failed>)r$r�r�r1rrrrR�s
�zBaseProxy.__str__�NNNTF)r8r:r;r<r�rZForkAwareThreadLockrr0r"r$r'rr
r*rrr/r9rRrrrrr�s$
�)	

rcCs�tt��dd�}|r*|j|jkr*t�d|�d|d<|j|jvr*|j|j|j|j<|�	dd�o8tt��dd�}|||fd|i|��S)	z5
    Function used for unpickling proxy objects.
    r{Nz*Rebuild a proxy owned by manager, token=%rTr rcZ_inheritingF)
rrrzr-rr�r.rprn�pop)rWr�rtrEr�rcrrrr-�s

��r-cCsnt|�}z|||fWStyYnwi}|D]}td||f|�qt|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�)r r��_cacheZdicZmeth�	ProxyTyperrr�
MakeProxyType�s"���r5cCs�t|d}|dur%||j|d�}zt|dd|f�}W|��n|��w|dur0|dur0|j}|dur9t��j}td|j	|�}	|	||||||d�}
d|
_
|
S)z*
    Return an auto-proxy for `token`
    rNr�r_z
AutoProxy[%s])rrkrcr T)rlr-rHr�r�rrzrkr5r,r,)r�rtrrkr�rcr r�r�r4rrrrr�s 

�rc@r)�	NamespacecKs|j�|�dSr)r�updater.rrrr0�r3zNamespace.__init__cCsZt|j���}g}|D]\}}|�d�s|�d||f�q|��d|jjd�|�fS)NrYz%s=%rz%s(%s)z, )	r&rr#�
startswithrUr�r7r8r�)r/r#rVr r�rrrr9�s
�zNamespace.__repr__N)r8r:r;r0r9rrrrr6�rr6c@s8eZdZddd�Zdd�Zdd�Zdd	�Zeee�Zd
S)�ValueTcC�||_||_dSr)�	_typecode�_value)r/rr��lockrrrr0��
zValue.__init__cCr�r�r<r1rrrr��sz	Value.getcCs
||_dSrr?�r/r�rrrr���
z	Value.setcCsdt|�j|j|jfS)Nz
%s(%r, %r))rr8r;r<r1rrrr9�szValue.__repr__N�T)	r8r:r;r0r�r�r9rr�rrrrr9�s
r9cCst�||�Sr)r)r�sequencer=rrr�Array�r�rDc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�
IteratorProxy)�__next__r?�throwr�cC�|Srrr1rrr�__iter__r�zIteratorProxy.__iter__cG�|�d|�S)NrFr&�r/rDrrrrF
r�zIteratorProxy.__next__cGrJ)Nr?r&rKrrrr?r�zIteratorProxy.sendcGrJ)NrGr&rKrrrrGr�zIteratorProxy.throwcGrJ)Nr�r&rKrrrr�r�zIteratorProxy.closeN)	r8r:r;r�rIrFr?rGr�rrrrrEsrEc@s2eZdZdZddd�Zdd�Zdd	�Zd
d�ZdS)
�
AcquirerProxy)�acquire�releaseTNcCs"|dur|fn||f}|�d|�S�NrMr&)r/Zblockingr�rDrrrrMszAcquirerProxy.acquirecCr%�NrNr&r1rrrrNrAzAcquirerProxy.releasecCr%rOr&r1rrrr�rAzAcquirerProxy.__enter__cCr%rPr&r�rrrr�rAzAcquirerProxy.__exit__)TN)r8r:r;r�rMrNr�r�rrrrrLs
rLc@s6eZdZdZddd�Zd
dd�Zdd	�Zdd
d�ZdS)�ConditionProxy)rMrNr��notify�
notify_allNcC�|�d|f�S�Nr�r&r�rrrr�#r*zConditionProxy.waitrcCrT)NrRr&)r/�nrrrrR%r*zConditionProxy.notifycCr%)NrSr&r1rrrrS'rAzConditionProxy.notify_allcCsj|�}|r|S|durt��|}nd}d}|s3|dur)|t��}|dkr)	|S|�|�|�}|r|S)Nr)�time�	monotonicr�)r/Z	predicater�rGZendtimeZwaittimerrr�wait_for)s"
��zConditionProxy.wait_forr)r)r8r:r;r�r�rRrSrYrrrrrQ!s

rQc@s2eZdZdZdd�Zdd�Zdd�Zdd	d
�ZdS)�
EventProxy)r�r�rr�cCr%)Nr�r&r1rrrr�>rAzEventProxy.is_setcCr%�Nr�r&r1rrrr�@rAzEventProxy.setcCr%)Nrr&r1rrrrBrAzEventProxy.clearNcCrTrUr&r�rrrr�Dr*zEventProxy.waitr)r8r:r;r�r�r�rr�rrrrrZ<srZc@sNeZdZdZddd�Zdd�Zdd�Zed	d
��Zedd��Z	ed
d��Z
dS)�BarrierProxy)�__getattribute__r��abort�resetNcCrTrUr&r�rrrr�Jr*zBarrierProxy.waitcCr%)Nr^r&r1rrrr^LrAzBarrierProxy.abortcCr%)Nr_r&r1rrrr_NrAzBarrierProxy.resetcC�|�dd�S)Nr])�partiesr&r1rrrraP�zBarrierProxy.partiescCr`)Nr])�	n_waitingr&r1rrrrcSrbzBarrierProxy.n_waitingcCr`)Nr])�brokenr&r1rrrrdVrbzBarrierProxy.brokenr)r8r:r;r�r�r^r_rrarcrdrrrrr\Hs


r\c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�NamespaceProxy)r]�__setattr__�__delattr__cCs0|ddkrt�||�St�|d�}|d|f�S)NrrYr$r])�objectr]�r/r
�
callmethodrrr�__getattr__]�zNamespaceProxy.__getattr__cCs4|ddkr
t�|||�St�|d�}|d||f�S)NrrYr$rf)rhrfr])r/r
r�rjrrrrfbszNamespaceProxy.__setattr__cCs0|ddkrt�||�St�|d�}|d|f�S)NrrYr$rg)rhrgr]rirrrrggrlzNamespaceProxy.__delattr__N)r8r:r;r�rkrfrgrrrrre[s
rec@s4eZdZdZdd�Zdd�Zeee�Zee	j
�ZdS)�
ValueProxy)r�r�cCr%)Nr�r&r1rrrr�prAzValueProxy.getcCrTr[r&r@rrrr�rr*zValueProxy.setN)r8r:r;r�r�r�rr�r�types�GenericAlias�__class_getitem__rrrrrmns
rm�
BaseListProxy)�__add__�__contains__�__delitem__�__getitem__�__len__�__mul__�__reversed__�__rmul__�__setitem__rU�count�extend�index�insertr1�remove�reverser��__imul__c@r)�	ListProxycC�|�d|f�|S)Nr|r&r@rrr�__iadd__��zListProxy.__iadd__cCr�)Nr�r&r@rrrr��r�zListProxy.__imul__N)r8r:r;r�r�rrrrr�sr��	DictProxy)rsrtrurIrvrzrrr�r#r$r1�popitem�
setdefaultr7r%rI�Iterator�
ArrayProxy)rvrurz�	PoolProxy)Zapply�apply_asyncr��imap�imap_unorderedr��map�	map_async�starmap�
starmap_asyncr�ZAsyncResult)r�r�r�r�r�c@r)r�cCrHrrr1rrrr��r�zPoolProxy.__enter__cCr�r)r�r�rrrr��r�zPoolProxy.__exit__N)r8r:r;r�r�rrrrr��rc@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)r8r:r;r<rrrrr�sr�QueueZ
JoinableQueuerxrr�RLock�	Semaphore�BoundedSemaphore�	Condition�Barrier�Poolr&r�)r�r	)r	c@sLeZdZdZgfdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�_SharedMemoryTrackerz+Manages one or more shared memory segments.cCr:r�Zshared_memory_context_name�
segment_names)r/r r�rrrr0�r>z_SharedMemoryTracker.__init__cCs(t�d|�dt����|j�|�dS)z6Adds the supplied shared memory block name to tracker.zRegister segment � in pid N)rr�rr�rU�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�rr�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��s�z_SharedMemoryTracker.unlinkcCs(t�d|jj�dt����|��dS)NzCall z.__del__ in )rr�r7r8rr�r1rrr�__del__�sz_SharedMemoryTracker.__del__cCs|j|jfSrr�r1rrrr2�r�z!_SharedMemoryTracker.__getstate__cCs|j|�dSr)r0r4rrrr6�r*z!_SharedMemoryTracker.__setstate__N)r8r:r;r<r0r�r�r�r�r2r6rrrrr��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�rt�|�}td|�dt����|_	t
�dt����dS)NZshm_rYz"SharedMemoryServer started by pid )r[r0r-rLrh�os�fsdecoder�r�shared_memory_contextrr�)r/rD�kwargsr-rrrr0�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�rir�r[r])r/rBr,rDr�rrrr]s
zSharedMemoryServer.createcCs|j��t�||�S)zACall unlink() on all tracked shared memory, terminate the Server.)r�r�r[r\r�rrrr\s
zSharedMemoryServer.shutdowncC�|j�|�dS)z?Adds the supplied shared memory block name to Server's tracker.N)r�r��r/rBr�rrrr�sz SharedMemoryServer.track_segmentcCr�)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)r8r:r;r[r�r0r]r\r�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_runningrr0rr�r7r8r)r/rDr�r�rrrr0/s

zSharedMemoryManager.__init__cCst�|jj�dt����dS)Nz.__del__ by pid )rr�r7r8rr1rrrr�;szSharedMemoryManager.__del__cCsd|jjtjkr&|jjtjkrtd��|jjtjkrtd��td�|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�rOr�r�r�r�r�r1rrrr�?s��zSharedMemoryManager.get_servercCs�|j|j|jd��/}tjdd|d�}zt|dd|jf�Wnty/}z|��|�d}~wwWd�|S1s;wY|S)zoReturns a new SharedMemory instance with the specified size in
            bytes, to be tracked by the manager.r�NT)r]�sizer�)	r�r�r�rr�rHr �
BaseExceptionr�)r/r�r�Zsmsr�rrrr�Ls���
��z SharedMemoryManager.SharedMemorycCs�|j|j|jd��.}t�|�}zt|dd|jjf�Wnty.}z|j�	�|�d}~wwWd�|S1s:wY|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�
ShareableListrHZshmr r�r�)r/rCr�Zslr�rrrr�Xs

���
��z!SharedMemoryManager.ShareableListN)r8r:r;r<r�r�r0r�r�r�r�rrrrr#s	
r0rB)U�__all__r�rqr�r�queuerWrnr�rr�rr�r	�contextr
rrr
rrrr�ImportErrorZ	HAS_SHMEMrUrrZ
view_typesr&r)Z	view_typerhrrHrAr�rPrXrZr[r�rurvZXmlListenerZ	XmlClientrlrr�rrr-r5rr6r9rDrErLrQrZr\rermrqr�r�rr�Z
BasePoolProxyr�rr�rxrrr�r�r�r�r�r�r�r�r�rrrrr�<module>s�
�


P

�	w
4
�



	�

�

�%-�