Sh3ll
OdayForums


Server : Apache
System : Linux server1.cgrithy.com 3.10.0-1160.95.1.el7.x86_64 #1 SMP Mon Jul 24 13:59:37 UTC 2023 x86_64
User : nobody ( 99)
PHP Version : 8.1.23
Disable Function : NONE
Directory :  /opt/alt/python38/lib64/python3.8/multiprocessing/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/alt/python38/lib64/python3.8/multiprocessing/__pycache__/shared_memory.cpython-38.pyc
U

��,aD�@s�dZddgZddlmZddlZddlZddlZddlZddlZej	dkrXddl
Z
dZnddlZdZej
ejBZd	Zer~d
ZndZdd
�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�z/psm_Zwnsm_cCsBttt�d}|dks td��tt�|�}t|�tks>t�|S)z6Create a random filename for the shared memory object.�z_SHM_NAME_PREFIX too long)�_SHM_SAFE_NAME_LENGTH�len�_SHM_NAME_PREFIX�AssertionError�secretsZ	token_hex)�nbytes�name�r�B/opt/alt/python38/lib64/python3.8/multiprocessing/shared_memory.py�_make_filename&s
rc@s�eZdZdZdZdZdZdZej	Z
dZer.dndZ
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
	Csl|dkstd��|r0ttjB|_|dkr0td��|dkrL|jtj@sLtd��t�rH|dkr�t�}ztj	||j|j
d�|_Wntk
r�YqZYnX||_
q�qZn.|jr�d|n|}tj	||j|j
d�|_||_
z<|r�|r�t�|j|�t�|j�}|j}t�|j|�|_Wn tk
�r*|���YnXddlm}||j
d	��n|�r�|dk�r^t�n|}t�tjtjtj|d
?d@|d@|�}zXt��}|tjk�r�|dk	�r�tt j!t�"t j!�|tj��nW��qNtjd||d
�|_W5t�|�X||_
�qV�qNnX||_
t�#tj$d|�}zt�%|tj$ddd�}	W5t�|�Xt�&|	�}tjd||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=True)�mode�/�)�register�
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�unlink�resource_trackerr�_winapiZCreateFileMappingZINVALID_HANDLE_VALUEZNULLZPAGE_READWRITEZCloseHandleZGetLastErrorZERROR_ALREADY_EXISTS�errnoZEEXIST�strerrorZOpenFileMappingZ
FILE_MAP_READZ
MapViewOfFileZVirtualQuerySize�_size�
memoryview�_buf)
�selfr�create�sizeZstatsrZ	temp_nameZh_mapZlast_error_codeZp_bufrrr�__init__Is��
�
�

�
��
zSharedMemory.__init__cCs&z|��Wntk
r YnXdS�N)�closer+�r4rrr�__del__�szSharedMemory.__del__cCs|j|jd|jffS)NF)�	__class__rr6r:rrr�
__reduce__�s��zSharedMemory.__reduce__cCs|jj�d|j�d|j�d�S)N�(z, size=�))r<�__name__rr6r:rrr�__repr__�szSharedMemory.__repr__cCs|jS)z4A memoryview of contents of the shared memory block.)r3r:rrr�buf�szSharedMemory.bufcCs.|j}tr*|jr*|j�d�r*|jdd�}|S)z4Unique name that identifies the shared memory block.rrN)r$rr%�
startswith)r4Z
reported_namerrrr�s

zSharedMemory.namecCs|jS)zSize in bytes.)r1r:rrrr6�szSharedMemory.sizecCsX|jdk	r|j��d|_|jdk	r4|j��d|_trT|jdkrTt�|j�d|_dS)zkCloses access to the shared memory from this instance but does
        not destroy the shared memory block.Nrr)r3�releaser*r9rr"rr:rrrr9�s



zSharedMemory.closecCs2tr.|jr.ddlm}t�|j�||jd�dS)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.r)�
unregisterrN)rr$r-rEr Z
shm_unlink)r4rErrrr,�s
zSharedMemory.unlink)NFr)r@�
__module__�__qualname__�__doc__r$r"r*r3rrrr!rr%r7r;r=rA�propertyrBrr6r9r,rrrrr0s(
l




�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!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|Sr8r��valuerrr�<lambda>
�zShareableList.<lambda>cCs|�d��t�S�N�)�rstrip�decode�	_encodingrNrrrrPrQcCs
|�d�SrR)rTrNrrrrPrQcCsdSr8r)Z_valuerrrrP
rQ)rrr�cCs:t|ttdjf�sdSt|t�r$dSt|t�r2dSdSdS)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.NrrrrW)�
isinstance�str�bytesr<rNrrr�_extract_recreation_codes

z&ShareableList._extract_recreation_code�rcs�|dk	r��fdd�|D�}t|��_tdd�|D���jks@t�t�fdd�|D���_�fdd�|D�}t�d�jd�	|��j
�j�}nd	}|dk	r�|dkr�t|��_
nt|d
|d��_
|dk	�rjt�tjd�j�j
jd�jf�j��tjd�	|��j
j�jf�fd
d�|D���tj�j
�j
j�jf�fdd�|D���tj�j�j
j�jf|��n t���_t��j�j
jd	��_dS)NcsPg|]H}t|ttf�s$�jt|�n&�jt|��jt|��jdf�qS)r)rXrYrZ�_types_mapping�type�
_alignmentr	��.0�itemr:rr�
<listcomp> s���z*ShareableList.__init__.<locals>.<listcomp>css|]}t|�dkVqdS)rMN)r	�ra�fmtrrr�	<genexpr>)sz)ShareableList.__init__.<locals>.<genexpr>c3s0|](}|ddkr�jnt|dd��VqdS)r�sN)r_�intrdr:rrrf*s�csg|]}��|��qSr)r[r`r:rrrc.srK�rMT)r5r6rc3s&|]}t|t�r|���n|VqdSr8)rXrY�encode�ra�v��_encrrrfMsc3s|]}|���VqdSr8)rjrkrmrrrfSs)r	�	_list_len�sumr�tuple�_allocated_bytes�structZcalcsize�_format_size_metainfo�join�_format_packing_metainfo�_format_back_transform_codesr�shmrV�	pack_intorB�_offset_data_start�_offset_packing_formats�_offset_back_transform_codes�unpack_from)r4ZsequencerZ_formatsZ_recreation_codesZrequested_sizer)rnr4rr7s|
�
�

�����
��������
�zShareableList.__init__cCsj|dkr|n||j}||jks*|jdkr2td��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.�8srMrS)
ro�
IndexErrorrsr}rxrBr{rTrUrV)r4�positionrlre�
fmt_as_strrrr�_get_packing_formatds��

z!ShareableList._get_packing_formatcCs\|dkr|n||j}||jks*|jdkr2td��t�d|jj|j|�d}|j|}|S)z9Gets the back transformation function for a single value.rr~�b)ror�rsr}rxrBr|�_back_transforms_mapping)r4r��transform_codeZtransform_functionrrr�_get_back_transformts��
z!ShareableList._get_back_transformcCs~|dkr|n||j}||jks*|jdkr2td��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~rrMr�N)ror�rsryrxrBr{rjrVr[r|)r4r�r�rOr�rrr�!_set_packing_format_and_transform�s �
�z/ShareableList._set_packing_format_and_transformcCsjz6|jt|jd|��}t�|�|�|jj|�\}Wntk
rRtd��YnX|�	|�}||�}|S)Nzindex out of range)
rzrprrrsr}r�rxrBr�r�)r4r��offsetrlZback_transformrrr�__getitem__�s��

zShareableList.__getitem__cCs�z&|jt|jd|��}|�|�}Wntk
rBtd��YnXt|ttf�sf|jt	|�}|}nZt|t�rz|�
t�n|}t|�|j|kr�t
d��|ddkr�|}n|jt|j|f}|�|||�t�||jj||�dS)Nzassignment index out of rangez(bytes/str item exceeds available storagerrg)rzrprrr�r�rXrYrZr]r^rjrVr	rr�rsryrxrB)r4r�rOr�Zcurrent_formatZ
new_formatZ
encoded_valuerrr�__setitem__�s6�����zShareableList.__setitem__cCst|j|jjd�dfS)Nr\r)rr<rxrr:rrrr=�szShareableList.__reduce__cCst�d|jjd�dS)NrKr)rsr}rxrBr:rrr�__len__�szShareableList.__len__cCs"|jj�dt|��d|jj�d�S)Nr>z, name=r?)r<r@�listrxrr:rrrrA�szShareableList.__repr__csd��fdd�t�j�D��S)z>The struct packing format used by all currently stored values.ric3s|]}��|�VqdSr8)r�)ra�ir:rrrf�sz'ShareableList.format.<locals>.<genexpr>)ru�rangeror:rr:r�format�s�zShareableList.formatcCs|j�d�S)z=The struct packing format used for metainfo on storage sizes.rK�ror:rrrrt�sz#ShareableList._format_size_metainfocCs
d|jS)z?The struct packing format used for the values' packing formats.rr�r:rrrrv�sz&ShareableList._format_packing_metainfocCs
d|jS)z?The struct packing format used for the values' back transforms.r�r�r:rrrrw�sz*ShareableList._format_back_transform_codescCs|jddS)NrrMr�r:rrrrz�sz ShareableList._offset_data_startcCs|jt|j�Sr8)rzrprrr:rrrr{�sz%ShareableList._offset_packing_formatscCs|j|jdS)NrM)r{ror:rrrr|�sz*ShareableList._offset_back_transform_codescst�fdd�|D��S)zCL.count(value) -> integer -- return number of occurrences of value.c3s|]}�|kVqdSr8r)ra�entryrNrrrf�sz&ShareableList.count.<locals>.<genexpr>)rp)r4rOrrNr�count�szShareableList.countcCs4t|�D]\}}||kr|Sqt|�d���dS)zpL.index(value) -> integer -- return first index of value.
        Raises ValueError if the value is not present.z not in this containerN)�	enumerater)r4rOr�r�rrr�index�s
zShareableList.index)N)"r@rFrGrHrh�float�boolrYrZr<r]r_r��staticmethodr[r7r�r�r�r�r�r=r�rArIr�rtrvrwrzr{r|r�r�rrrrr�s^
��

F






)rH�__all__�	functoolsrr)rr/rsrrr.rr �O_CREATrrrr
rrrVrrrrr�<module>s,

E

ZeroDay Forums Mini