Edit File: resource_sharer.cpython-36.pyc
3 � \�������������������@���s����d�dl�Z�d�dlZd�dlZd�dlZd�dlZddlmZ�ddlmZ�ddlm Z �dgZ ejdkrxe dg7�Z G�d d��de�Z ne d g7�Z G�dd ��d e�ZG�dd ��d e�Ze��ZejZdS�)�����N����)�process)� reduction)�util�stopZwin32� DupSocketc���������������@���s ���e�Zd�ZdZdd��Zdd��ZdS�)r���zPicklable wrapper for a socket.c����������������s(���|j�������fdd�}tj|��j�|�_d�S�)Nc����������������s�����j�|�}|�j|��d�S�)N)�shareZ send_bytes)�conn�pidr���)�new_sock���7/usr/lib64/python3.6/multiprocessing/resource_sharer.py�send���s���� z DupSocket.__init__.<locals>.send)�dup�_resource_sharer�register�close�_id)�selfZsockr���r���)r���r ����__init__���s����zDupSocket.__init__c���������� ���C���s*���t�j|�j��}|j��}tj|�S�Q�R�X�dS�)z1Get the socket. This should only be called once.N)r����get_connectionr���Z recv_bytes�socketZ fromshare)r���r ���r���r���r���r ����detach$���s����zDupSocket.detachN)�__name__� __module__�__qualname__�__doc__r���r���r���r���r���r ���r������s����DupFdc���������������@���s ���e�Zd�ZdZdd��Zdd��ZdS�)r���z-Wrapper for fd which can be used at any time.c����������������s4���t�j|�����fdd�}��fdd�}tj||�|�_d�S�)Nc����������������s���t�j|���|��d�S�)N)r���Zsend_handle)r ���r ���)�new_fdr���r ���r���1���s����zDupFd.__init__.<locals>.sendc������������������s���t�j����d�S�)N)�osr���r���)r���r���r ���r���3���s����zDupFd.__init__.<locals>.close)r���r���r���r���r���)r����fdr���r���r���)r���r ���r���/���s���� zDupFd.__init__c���������� ���C���s"���t�j|�j��}tj|�S�Q�R�X�dS�)z-Get the fd. This should only be called once.N)r���r���r���r���Zrecv_handle)r���r ���r���r���r ���r���7���s����zDupFd.detachN)r���r���r���r���r���r���r���r���r���r ���r���-���s���c���������������@���sN���e�Zd�ZdZdd��Zdd��Zedd���Zdd d �Zdd��Z d d��Z dd��ZdS�)�_ResourceSharerz-Manager for resouces using background thread.c�������������C���s@���d|�_�i�|�_g�|�_tj��|�_d�|�_d�|�_d�|�_t j |�tj��d�S�)Nr���) �_key�_cache� _old_locks� threading�Lock�_lock� _listener�_address�_threadr���Zregister_after_forkr!���� _afterfork)r���r���r���r ���r���?���s���� z_ResourceSharer.__init__c���������� ���C���sN���|�j��>�|�jdkr|�j���|��jd7��_||f|�j|�j<�|�j|�jfS�Q�R�X�dS�)z+Register resource, returning an identifier.Nr���)r'���r)����_startr"���r#���)r���r���r���r���r���r ���r���I���s���� z_ResourceSharer.registerc�������������C���s<���ddl�m}�|�\}}||tj��jd�}|j|tj��f��|S�)z<Return connection from which to receive identified resource.r���)�Client)�authkey)� connectionr-���r����current_processr.���r���r����getpid)Zidentr-����address�key�cr���r���r ���r���R���s ����z_ResourceSharer.get_connectionNc�������������C���s����ddl�m}�|�j���|�jdk r�||�jtj��jd�}|jd��|j���|�j j |��|�j j��rdtj d��|�jj���d|�_ d|�_d|�_x |�jj��D�]\}\}}|���q�W�|�jj���W�dQ�R�X�dS�)z:Stop the background thread and clear registered resources.r���)r-���N)r.���z._ResourceSharer thread did not stop when asked)r/���r-���r'���r)���r���r0���r.���r���r���r*����joinZis_aliver���Zsub_warningr(���r#����items�clear)r���Ztimeoutr-���r4���r3���r���r���r���r���r ���r���[���s"���� z_ResourceSharer.stopc�������������C���sn���x |�j�j��D�]\}\}}|���qW�|�j�j���|�jj|�j��tj��|�_|�jd�k rX|�jj ���d�|�_d�|�_ d�|�_d�S�)N)r#���r6���r7���r$����appendr'���r%���r&���r(���r���r)���r*���)r���r3���r���r���r���r���r ���r+���p���s���� z_ResourceSharer._afterforkc�������������C���sf���ddl�m}�|�jd�kst�tjd��|tj��jd�|�_|�jj |�_ tj|�j d�}d|_|j���||�_d�S�)Nr���)�Listenerz0starting listener and thread for sending handles)r.���)�targetT)r/���r9���r(����AssertionErrorr����debugr���r0���r.���r2���r)���r%���ZThread�_serveZdaemon�startr*���)r���r9����tr���r���r ���r,���~���s���� z_ResourceSharer._startc�������������C���s����t�td�r tjtjtdtj���x�y\|�jj���H}|j��}|d�krBP�|\}}|�j j |�\}}z|||��W�d�|���X�W�d�Q�R�X�W�q"���tj��s�t jt j�����Y�q"X�q"W�d�S�)N�pthread_sigmaskr���)�hasattr�signalr@���� SIG_BLOCK�range�NSIGr(���ZacceptZrecvr#����popr���Z is_exiting�sys� excepthook�exc_info)r���r ����msgr3���Zdestination_pidr���r���r���r���r ���r=�������s ���� z_ResourceSharer._serve)N)r���r���r���r���r���r����staticmethodr���r���r+���r,���r=���r���r���r���r ���r!���=���s��� r!���)r���rB���r���rG���r%�����r����contextr���r����__all__�platform�objectr���r���r!���r���r���r���r���r���r ����<module>���s ��� `