
    d                         d dl Z d dlZd dlZd dlZd dlZddlmZ ddlmZ ddlm	Z	 dgZ
ej        dk    re
dgz  Z
 G d	 de          Zne
d
gz  Z
 G d d
e          Z G d de          Z e            Zej        ZdS )    N   )process)	reduction)utilstopwin32	DupSocketc                       e Zd ZdZd Zd ZdS )r	   zPicklable wrapper for a socket.c                     |                                 fd}t                              |j                  | _        d S )Nc                 \                         |          }|                     |           d S N)share
send_bytes)connpidr   new_socks      1  /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/multiprocessing/resource_sharer.pysendz DupSocket.__init__.<locals>.send   s,     s++&&&&&    )dup_resource_sharerregisterclose_id)selfsockr   r   s      @r   __init__zDupSocket.__init__   sH    xxzzH' ' ' ' ' (00x~FFDHHHr   c                     t                               | j                  5 }|                                }t	          j        |          cddd           S # 1 swxY w Y   dS )z1Get the socket.  This should only be called once.N)r   get_connectionr   
recv_bytessocket	fromshare)r   r   r   s      r   detachzDupSocket.detach$   s    !00:: /d))'../ / / / / / / / / / / / / / / / / /s   (AAAN__name__
__module____qualname____doc__r   r#    r   r   r	   r	      s;        --	G 	G 	G	/ 	/ 	/ 	/ 	/r   DupFdc                       e Zd ZdZd Zd ZdS )r*   z-Wrapper for fd which can be used at any time.c                     t          j        |          fd}fd}t                              ||          | _        d S )Nc                 4    t          j        | |           d S r   )r   send_handle)r   r   new_fds     r   r   zDupFd.__init__.<locals>.send1   s    %dFC88888r   c                  0    t          j                    d S r   )osr   )r/   s   r   r   zDupFd.__init__.<locals>.close3   s         r   )r1   r   r   r   r   )r   fdr   r   r/   s       @r   r   zDupFd.__init__/   s]    VBZZF9 9 9 9 9! ! ! ! !'00u==DHHHr   c                     t                               | j                  5 }t          j        |          cddd           S # 1 swxY w Y   dS )z-Get the fd.  This should only be called once.N)r   r   r   r   recv_handle)r   r   s     r   r#   zDupFd.detach7   s    !00:: 3d ,T223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3s   AAANr$   r)   r   r   r*   r*   -   s8        ;;	> 	> 	>	3 	3 	3 	3 	3r   c                   N    e Zd ZdZd Zd Zed             Zd
dZd Z	d Z
d	 ZdS )_ResourceSharerz.Manager for resources using background thread.c                     d| _         i | _        t          j                    | _        d | _        d | _        d | _        t          j	        | t          j                   d S )Nr   )_key_cache	threadingLock_lock	_listener_address_threadr   register_after_forkr6   
_afterfork)r   s    r   r   z_ResourceSharer.__init__?   sP    	^%%
 'ABBBBBr   c                     | j         5  | j        |                                  | xj        dz  c_        ||f| j        | j        <   | j        | j        fcddd           S # 1 swxY w Y   dS )z+Register resource, returning an identifier.Nr   )r<   r>   _startr8   r9   )r   r   r   s      r   r   z_ResourceSharer.registerH   s    Z 	. 	.}$IINII&*E]DK	"M49-	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   A
AA#&A#c                     ddl m} | \  }} ||t          j                    j                  }|                    |t          j                    f           |S )z<Return connection from which to receive identified resource.r   Clientauthkey)
connectionrF   r   current_processrH   r   r1   getpid)identrF   addresskeycs        r   r   z_ResourceSharer.get_connectionQ   sa     	'&&&&&F7G$;$=$=$EFFF	RY[[!"""r   Nc                 x   ddl m} | j        5  | j         || j        t	          j                    j                  }|                    d           |                                 | j	        
                    |           | j	                                        rt          j        d           | j                                         d| _	        d| _        d| _        | j                                        D ]\  }\  }} |             | j                                         ddd           dS # 1 swxY w Y   dS )z:Stop the background thread and clear registered resources.r   rE   NrG   z._ResourceSharer thread did not stop when asked)rI   rF   r<   r>   r   rJ   rH   r   r   r?   joinis_aliver   sub_warningr=   r9   itemsclear)r   timeoutrF   rO   rN   r   r   s          r   r   z_ResourceSharer.stopZ   s   &&&&&&Z 	$ 	$}(F4=#*#:#<#<#DF F Ft			!!'***<((** <$ &; < < <$$&&&# $!%*.+*;*;*=*=  &C$EGGGG!!###!	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   DD//D36D3c                 ,   | j                                         D ]\  }\  }} |             | j                                          | j                                         | j        | j                                         d | _        d | _        d | _        d S r   )	r9   rT   rU   r<   _at_fork_reinitr=   r   r>   r?   )r   rN   r   r   s       r   rA   z_ResourceSharer._afterforko   s    "&+"3"3"5"5 	 	C$EGGGG
""$$$>%N  """r   c                 D   ddl m} | j        
J d            t          j        d            |t          j                    j                  | _        | j        j        | _	        t          j        | j                  }d|_        |                                 || _        d S )Nr   )ListenerzAlready have Listenerz0starting listener and thread for sending handlesrG   )targetT)rI   rZ   r=   r   debugr   rJ   rH   rM   r>   r:   Thread_servedaemonstartr?   )r   rZ   ts      r   rC   z_ResourceSharer._startz   s    ((((((~%%'>%%%
EFFF!'*A*C*C*KLLL.DK000				r   c                 D   t          t          d          r0t          j        t          j        t          j                               	 	 | j                                        5 }|                                }|	 d d d            d S |\  }}| j        	                    |          \  }}	  |||            |             n#  |             w xY w	 d d d            n# 1 swxY w Y   n9#  t          j                    st          j        t          j                      Y nxY w)Npthread_sigmask)hasattrsignalrc   	SIG_BLOCKvalid_signalsr=   acceptrecvr9   popr   
is_exitingsys
excepthookexc_info)r   r   msgrN   destination_pidr   r   s          r   r^   z_ResourceSharer._serve   so   6,-- 	M"6#3V5I5K5KLLL	44^**,, 	 ))++C{	  	  	  	  	  	  	  	  ,/(C"&+//#"6"6KD% T?333	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 4(( 4NCLNN33	4sT   C( !C9C( "C)C 5C CCC( C  C( #C $C( (4Dr   )r%   r&   r'   r(   r   r   staticmethodr   r   rA   rC   r^   r)   r   r   r6   r6   =   s        88C C C. . .   \$ $ $ $*	 	 		 	 	4 4 4 4 4r   r6   )r1   re   r!   rl   r:    r   contextr   r   __all__platformobjectr	   r*   r6   r   r   r)   r   r   <module>rw      sE   
			   



                      ( <7}G/ / / / /F / / / /  yG3 3 3 3 3 3 3 3 Y4 Y4 Y4 Y4 Y4f Y4 Y4 Y4x #?$$ r   