a XC?hG @ s d Z ddgZddlmZ ddlZddlZddlZddlZddlZddl Z ej dkr`ddlZdZnddl Z dZejejB Zd Zerd ZndZdd ZG dd dZdZG dd dZdS )zProvides shared memory for direct access across processes. The API of this package is currently provisional. Refer to the documentation for details. SharedMemory ShareableList )partialNntFT z/psm_Zwnsm_c C s" t tt d } tt| }|S )z6Create a random filename for the shared memory object. )_SHM_SAFE_NAME_LENGTHlen_SHM_NAME_PREFIXsecretsZ token_hex)nbytesname r B/opt/alt/python39/lib64/python3.9/multiprocessing/shared_memory.py_make_filename' s r c @ s e Zd ZdZdZdZdZdZej Z dZer.dndZ ddd Zd d Zdd Zdd Zedd Zedd Zedd Zdd Zdd ZdS )r a 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.Ni TFr c C s |dkst d|r0ttjB | _|dkr0t d|d u rL| jtj@ sLt dtrD|d u rt }ztj || j| j d| _W n ty Y qZY n0 || _ qqZn.| jrd| n|}tj || j| j d| _|| _ z<|r|rt| j| t| j}|j}t| j|| _W n ty& | Y n0 ddlm} || j d n*|r|d u rZt n|}ttjtjtj|d ? d@ |d@ |}zjt }|tjkr|d urttj t!tj |tjnW t"| qJtjd||d | _W t"| nt"| 0 || _ qnqJnb|| _ t#tj$d|}z"t%|tj$ddd} W t"| nt"| 0 t&| }tjd||d | _|| _'t(| j| _)d S )Nr z!'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_CREXosO_RDWR_flagsO_EXCL _USE_POSIXr _posixshmemZshm_open_mode_fdFileExistsError_name_prepend_leading_slash ftruncatefstatst_sizemmap_mmapOSErrorunlinkresource_trackerr _winapiZCreateFileMappingZINVALID_HANDLE_VALUEZNULLZPAGE_READWRITEZGetLastErrorZERROR_ALREADY_EXISTSerrnoZEEXISTstrerrorZCloseHandleZOpenFileMappingZ FILE_MAP_READZ MapViewOfFileZVirtualQuerySize_size memoryview_buf) selfr createsizeZstatsr Z temp_nameZh_mapZlast_error_codeZp_bufr r r __init__J s zSharedMemory.__init__c C s$ z| W n ty Y n0 d S N)closer* r3 r r r __del__ s zSharedMemory.__del__c C s | j | jd| jffS )NF) __class__r r5 r9 r r r __reduce__ s zSharedMemory.__reduce__c C s | j j d| jd| j dS )N(z, size=))r; __name__r r5 r9 r r r __repr__ s zSharedMemory.__repr__c C s | j S )z4A memoryview of contents of the shared memory block.)r2 r9 r r r buf s zSharedMemory.bufc C s. | j }tr*| jr*| j dr*| j dd }|S )z4Unique name that identifies the shared memory block.r r N)r# r r$ startswith)r3 Z reported_namer r r r s zSharedMemory.namec C s | j S )zSize in bytes.)r0 r9 r r r r5 s zSharedMemory.sizec C sX | j dur| j d| _ | jdur4| j d| _trT| jdkrTt| j d| _dS )zkCloses access to the shared memory from this instance but does not destroy the shared memory block.Nr r )r2 releaser) r8 r r! r r9 r r r r8 s zSharedMemory.closec C s2 t r.| jr.ddlm} t| j || jd dS )zRequests 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 ) unregisterr N)r r# r, rD r Z shm_unlink)r3 rD r r r r+ s zSharedMemory.unlink)NFr )r? __module____qualname____doc__r# r! r) r2 r r r r r r$ r6 r: r<