AlkantarClanX12

Your IP : 3.148.106.49


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

o

6��fH�@s�dZddgZddlmZddlZddlZddlZddlZddlZddl	Z	ej
dkr0ddlZdZnddl
Z
dZd	d
lmZejejBZdZerIdZnd
Zdd�ZGdd�d�ZdZGdd�d�ZdS)z�Provides shared memory for direct access across processes.

The API of this package is currently provisional. Refer to the
documentation for details.
�SharedMemory�
ShareableList�)�partialN�ntFT�)�resource_tracker�z/psm_Zwnsm_cCsBttt�d}|dksJd��tt�|�}t|�tksJ�|S)z6Create a random filename for the shared memory object.�z_SHM_NAME_PREFIX too long)�_SHM_SAFE_NAME_LENGTH�len�_SHM_NAME_PREFIX�secretsZ	token_hex)�nbytes�name�r�D/opt/alt/python310/lib64/python3.10/multiprocessing/shared_memory.py�_make_filename(s
rc@s�eZdZdZdZdZdZdZej	Z
dZerdndZ
ddd	�Zd
d�Zdd
�Zdd�Zedd��Zedd��Zedd��Zdd�Zdd�ZdS)ra�Creates a new shared memory block or attaches to an existing
    shared memory block.

    Every shared memory block is assigned a unique name.  This enables
    one process to create a shared memory block with a particular name
    so that a different process can attach to that same shared memory
    block using that same name.

    As a resource for sharing data across processes, shared memory blocks
    may outlive the original process that created them.  When one process
    no longer needs access to a shared memory block that might still be
    needed by other processes, the close() method should be called.
    When a shared memory block is no longer needed by any process, the
    unlink() method should be called to ensure proper cleanup.N���i�TFrc		Csx|dkstd��|rttjB|_|dkrtd��|dur&|jtj@s&td��tr�|durL	t�}z
tj	||j|j
d�|_Wn	tyFYq,w||_
	n|jrSd|n|}tj	||j|j
d�|_||_
z|ro|rot�|j|�t�|j�}|j}t�|j|�|_Wnty�|���wt�|j
d�n�|r�	|dur�t�n|}t�tjtjtj|d	?d
@|d
@|�}z1t��}|tjkr�|dur�ttj t�!tj �|tj��Wt�"|�q�tjd||d�|_Wt�"|�nt�"|�w||_
	n?||_
t�#tj$d
|�}zt�%|tj$ddd�}Wt�"|�nt�"|�wzt�&|�}Wt�'|�nt�'|�wtjd||d�|_||_(t)|j�|_*dS)Nrz!'size' must be a positive integerz4'size' must be a positive number different from zeroz&'name' can only be None if create=TrueT)�mode�/�
shared_memory� l��r)ZtagnameF)+�
ValueError�_O_CREX�os�O_RDWR�_flags�O_EXCL�
_USE_POSIXr�_posixshmemZshm_open�_mode�_fd�FileExistsError�_name�_prepend_leading_slash�	ftruncate�fstat�st_size�mmap�_mmap�OSError�unlinkr�register�_winapiZCreateFileMappingZINVALID_HANDLE_VALUEZNULLZPAGE_READWRITEZGetLastErrorZERROR_ALREADY_EXISTS�errnoZEEXIST�strerrorZCloseHandleZOpenFileMappingZ
FILE_MAP_READZ
MapViewOfFileZVirtualQuerySizeZUnmapViewOfFile�_size�
memoryview�_buf)	�selfr�create�sizeZstatsZ	temp_nameZh_mapZlast_error_codeZp_bufrrr�__init__Ks�����
�

����zSharedMemory.__init__cCs$z|��WdStyYdSw�N)�closer*�r3rrr�__del__�s
�zSharedMemory.__del__cCs|j|jd|jffS)NF)�	__class__rr5r9rrr�
__reduce__�s��zSharedMemory.__reduce__cCs|jj�d|j�d|j�d�S)N�(z, size=�))r;�__name__rr5r9rrr�__repr__�szSharedMemory.__repr__cC�|jS)z4A memoryview of contents of the shared memory block.)r2r9rrr�buf��zSharedMemory.bufcCs.|j}tr|jr|j�d�r|jdd�}|S)z4Unique name that identifies the shared memory block.rrN)r#rr$�
startswith)r3Z
reported_namerrrr�s

zSharedMemory.namecCrA)zSize in bytes.)r0r9rrrr5�rCzSharedMemory.sizecCs`|jdur
|j��d|_|jdur|j��d|_tr,|jdkr.t�|j�d|_dSdSdS)zkCloses access to the shared memory from this instance but does
        not destroy the shared memory block.Nrr)r2�releaser)r8rr!rr9rrrr8�s




�zSharedMemory.closecCs0tr|jrt�|j�t�|jd�dSdSdS)z�Requests that the underlying shared memory block be destroyed.

        In order to ensure proper cleanup of resources, unlink should be
        called once (and only once) across all processes which have access
        to the shared memory block.rN)rr#rZ
shm_unlinkr�
unregisterr9rrrr+�s
�zSharedMemory.unlink)NFr)r?�
__module__�__qualname__�__doc__r#r!r)r2rrrr rr$r6r:r<r@�propertyrBrr5r8r+rrrrr2s*
n




�utf8c@seZdZdZedededededdj	diZ
dZd	d
�dd
�dd
�d
d
�d�Ze
dd��Zd6dd�dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zed$d%��Zed&d'��Zed(d)��Zed*d+��Zed,d-��Zed.d/��Zed0d1��Zd2d3�Z d4d5�Z!e"e#j$�Z%dS)7ra�Pattern for a mutable list-like object shareable via a shared
    memory block.  It differs from the built-in list type in that these
    lists can not change their overall length (i.e. no append, insert,
    etc.)

    Because values are packed into a memoryview as bytes, the struct
    packing format for any storable value must require no more than 8
    characters to describe its format.�q�dzxxxxxxx?z%dsNzxxxxxx?x�cCs|Sr7r��valuerrr�<lambda>�zShareableList.<lambda>cCs|�d��t�S�N�)�rstrip�decode�	_encodingrOrrrrQscCs
|�d�SrS)rUrOrrrrQs
cCsdSr7r)Z_valuerrrrQrR)rrr	�cCs6t|ttdjf�sdSt|t�rdSt|t�rdSdS)z�Used in concert with _back_transforms_mapping to convert values
        into the appropriate Python objects when retrieving them from
        the list as well as when storing them.Nrrr	rX)�
isinstance�str�bytesr;rOrrr�_extract_recreation_codes

z&ShareableList._extract_recreation_code�rcs�|dus|durq|pd}�fdd�|D�}t|��_tdd�|D���jks(J�d}dg�_|D]}||ddkr<�jnt|dd��7}�j�|�q0�fd	d�|D�}t�d
�j	d�
|��j�j�}t
|d|d
��_nt
|��_|dur�t�tjd
�j	�jjd�jg�j�R�tjd�
|��jj�jg�fdd�|D��R�tj�j�jj�jg�fdd�|D��R�tj�j�jj�jg|�R�dSt���_tt��j	�jjd���_dS)NrcsPg|]$}t|ttf�s�jt|�n�jt|��jt|��jdf�qS)r)rYrZr[�_types_mapping�type�
_alignmentr��.0�itemr9rr�
<listcomp>-s����z*ShareableList.__init__.<locals>.<listcomp>css�|]	}t|�dkVqdS)rNN)r)rb�fmtrrr�	<genexpr>6s�z)ShareableList.__init__.<locals>.<genexpr>rr�scsg|]}��|��qSr)r\rar9rrrd?s
�rL�T)r4r5c3s(�|]}t|t�r|���n|VqdSr7)rYrZ�encode�rb�v��_encrrrfZs�&c3s�|]}|���VqdSr7)rirjrlrrrf`s�rN)r�	_list_len�sum�_allocated_offsetsr`�int�append�structZcalcsize�_format_size_metainfo�join�_format_packing_metainfo�_format_back_transform_codesr�shmrW�	pack_intorB�_offset_data_start�_offset_packing_formats�_offset_back_transform_codes�list�unpack_from)r3ZsequencerZ_formats�offsetreZ_recreation_codesZrequested_sizer)rmr3rr6*s�
�
&
�����
��������
�
�zShareableList.__init__cCsj|dkr|n||j}||jks|jdkrtd��t�d|jj|j|d�d}|�d�}|�t	�}|S)z>Gets the packing format for a single value stored in the list.r� Requested position out of range.�8srNrT)
rn�
IndexErrorrsr~rxrBr{rUrVrW)r3�positionrkre�
fmt_as_strrrr�_get_packing_formatss��

z!ShareableList._get_packing_formatcCsF||jks
|jdkrtd��t�d|jj|j|�d}|j|}|S)z9Gets the back transformation function for a single value.rr��b)rnr�rsr~rxrBr|�_back_transforms_mapping)r3r��transform_codeZtransform_functionrrr�_get_back_transform�s��
z!ShareableList._get_back_transformcCsh||jks
|jdkrtd��t�d|jj|j|d|�t��|�	|�}t�d|jj|j
||�dS)zvSets the packing format and back transformation code for a
        single value in the list at the specified position.rr�r�rNr�N)rnr�rsryrxrBr{rirWr\r|)r3r�r�rPr�rrr�!_set_packing_format_and_transform�s�
�z/ShareableList._set_packing_format_and_transformcCsr|dkr|n||j}z|j|j|}t�|�|�|jj|�\}Wnty-td��w|�	|�}||�}|S)Nrzindex out of range)
rnrzrprsr~r�rxrBr�r�)r3r�rrkZback_transformrrr�__getitem__�s
��
zShareableList.__getitem__c	Cs�|dkr|n||j}z|j|}|j|}|�|�}Wnty'td��wt|ttf�s9|jt	|�}|}n0|j|d|}t|t�rL|�
t�n|}t|�|krXt
d��|ddkra|}n|jt|f}|�|||�t�||jj||�dS)Nrzassignment index out of rangerz(bytes/str item exceeds available storagerrg)rnrprzr�r�rYrZr[r^r_rirWrrr�rsryrxrB)	r3r�rPZitem_offsetrZcurrent_formatZ
new_formatZ
encoded_valueZallocated_lengthrrr�__setitem__�s:

�����zShareableList.__setitem__cCst|j|jjd�dfS)Nr]r)rr;rxrr9rrrr<��zShareableList.__reduce__cCst�d|jjd�dS)NrLr)rsr~rxrBr9rrr�__len__�r�zShareableList.__len__cCs"|jj�dt|��d|jj�d�S)Nr=z, name=r>)r;r?r}rxrr9rrrr@�s"zShareableList.__repr__csd��fdd�t�j�D��S)z=The struct packing format used by all currently stored items.rhc3s�|]}��|�VqdSr7)r�)rb�ir9rrrf�s�

�z'ShareableList.format.<locals>.<genexpr>)ru�rangernr9rr9r�format�s�zShareableList.formatcCsd|jdS)z>The struct packing format used for the items' storage offsets.rLr�rnr9rrrrt�sz#ShareableList._format_size_metainfocC�
d|jS)z>The struct packing format used for the items' packing formats.r�r�r9rrrrv��
z&ShareableList._format_packing_metainfocCr�)z>The struct packing format used for the items' back transforms.r�r�r9rrrrw�r�z*ShareableList._format_back_transform_codescCs|jddS)Nr	rNr�r9rrrrz�sz ShareableList._offset_data_startcCs|j|jdS)Nr)rzrpr9rrrr{��z%ShareableList._offset_packing_formatscCs|j|jdS)NrN)r{rnr9rrrr|r�z*ShareableList._offset_back_transform_codescst�fdd�|D��S)zCL.count(value) -> integer -- return number of occurrences of value.c3s�|]}�|kVqdSr7r)rb�entryrOrrrf
s�z&ShareableList.count.<locals>.<genexpr>)ro)r3rPrrOr�countszShareableList.countcCs0t|�D]\}}||kr|Sqt|�d���)zpL.index(value) -> integer -- return first index of value.
        Raises ValueError if the value is not present.z not in this container)�	enumerater)r3rPr�r�rrr�indexs
�zShareableList.indexr7)&r?rGrHrIrq�float�boolrZr[r;r^r`r��staticmethodr\r6r�r�r�r�r�r<r�r@rJr�rtrvrwrzr{r|r�r��classmethod�types�GenericAlias�__class_getitem__rrrrr�sV��

I!







)rI�__all__�	functoolsrr(rr.rsr
r�rr-rrrhr�O_CREATrrr
rrrrWrrrrr�<module>s2

F