grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a ´iÜGã@s¶dZddgZddlmZddlZddlZddlZddlZddlZddl Z ej dkr`ddl Z dZ n ddl Z dZ ejejBZd Ze r†d Znd Zd 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_cCs"tttƒd}tt |¡}|S)z6Create a random filename for the shared memory object.é)Ú_SHM_SAFE_NAME_LENGTHÚlenÚ_SHM_NAME_PREFIXÚsecretsZ token_hex)ÚnbytesÚname©rú5/usr/lib64/python3.9/multiprocessing/shared_memory.pyÚ_make_filename'src@sŒeZdZdZdZdZdZdZej Z dZ e 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 Cs„|dkstdƒ‚|r0ttjB|_|dkr0tdƒ‚|durL|jtj@sLtdƒ‚t�rD|duržtƒ}ztj ||j|j d�|_ Wnt y�YqZYn0||_ qÌqZn.|jr¬d|n|}tj ||j|j d�|_ ||_ z<|rä|rät |j |¡t |j ¡}|j}t |j |¡|_Wnt�y&| ¡‚Yn0ddlm}||j d ƒ�n*|�r |du�rZtƒn|}t tjtjtj|d ?d @|d @|¡}zjt ¡}|tjk�rÐ|du�rÀt tj t !tj ¡|tjƒ‚nWt "|¡�qJtjd ||d �|_Wt "|¡n t "|¡0||_ �qn�qJnb||_ t #tj$d|¡}z"t %|tj$ddd¡} Wt "|¡n t "|¡0t &| ¡}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_READWRITEZ GetLastErrorZERROR_ALREADY_EXISTSÚerrnoÚEEXISTÚstrerrorZ CloseHandleZOpenFileMappingZ FILE_MAP_READZ MapViewOfFileZVirtualQuerySizeÚ_sizeÚ memoryviewÚ_buf) Úselfr ÚcreateÚsizeZstatsrZ temp_nameZh_mapZlast_error_codeZp_bufrrrÚ__init__Jsª ý   ý   ú   ü ý ýû zSharedMemory.__init__cCs$z | ¡WntyYn0dS©N)Úcloser*©r4rrrÚ__del__¶s  zSharedMemory.__del__cCs|j|jd|jffS)NF)Ú __class__r r6r:rrrÚ __reduce__¼s ýþzSharedMemory.__reduce__cCs|jj›d|j›d|j›d�S)Nú(z, size=ú))r<Ú__name__r r6r: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|jdur|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.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,rErZ shm_unlink)r4rErrrr+és   zSharedMemory.unlink)NFr)r@Ú __module__Ú __qualname__Ú__doc__r#r!r)r3rrrr rr$r7r;r=rAÚpropertyrBr r6r9r+rrrrr1s(  l     Úutf8c @seZdZdZedededededdj diZ dZ d d „d d „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|Sr8r©ÚvaluerrrÚózShareableList.cCs| d¡ t¡S©Nó)ÚrstripÚdecodeÚ _encodingrNrrrrPrQcCs | d¡SrR)rTrNrrrrPrQcCsdSr8r)Ú_valuerrrrPrQ)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.NrrrrX)Ú isinstanceÚstrÚbytesr<rNrrrÚ_extract_recreation_codes  z&ShareableList._extract_recreation_code©r cs¨|dus|durÆ|pd}‡fdd„|Dƒ}t|ƒˆ_d}dgˆ_|D]6}||ddkr\ˆjnt|dd…ƒ7}ˆj |¡qD‡fdd„|Dƒ}t dˆjd   |¡ˆj ˆj ¡}t |d |d �ˆ_ n t |ƒˆ_ |du�r€t‰tjdˆjˆj jdˆjgˆj¢RŽtjd   |¡ˆj jˆjg‡fd d „|Dƒ¢RŽtjˆj ˆj jˆjg‡fdd „|Dƒ¢RŽtjˆj ˆj jˆjg|¢RŽn$tˆƒˆ_tt ˆjˆj jd¡ƒˆ_dS)NrcsPg|]H}t|ttfƒs$ˆjt|ƒn&ˆjt|ƒˆjt|ƒˆjdf‘qS)r)rYrZr[Ú_types_mappingÚtypeÚ _alignmentr ©Ú.0Úitemr:rrÚ +s ü ÿ ÿz*ShareableList.__init__..rrÚscsg|]}ˆ |¡‘qSr)r\rar:rrrd=srKÚT)r5r6c3s&|]}t|tƒr| ˆ¡n|VqdSr8)rYrZÚencode©rbÚv©Ú_encrrÚ XrQz)ShareableList.__init__..c3s|]}| ˆ¡VqdSr8)rgrhrjrrrl^rQrM)r Ú _list_lenÚ_allocated_offsetsr`ÚintÚappendÚstructÚcalcsizeÚ_format_size_metainfoÚjoinÚ_format_packing_metainfoÚ_format_back_transform_codesrÚshmrVÚ pack_intorBÚ_offset_data_startÚ_offset_packing_formatsÚ_offset_back_transform_codesÚlistÚ unpack_from)r4Zsequencer Z_formatsÚoffsetÚfmtZ_recreation_codesZrequested_sizer)rkr4rr7(s€ ú & ÿÿþýÿ  üûýüýüýü  ýÿ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) rmÚ IndexErrorrqr}rwrBrzrTrUrV)r4ÚpositionrirÚ fmt_as_strrrrÚ_get_packing_formatqs ýü  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)rmr‚rqr}rwrBr{Ú_back_transforms_mapping)r4rƒÚ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�rMr†N) rmr‚rqrxrwrBrzrgrVr\r{)r4rƒr„rOrˆrrrÚ!_set_packing_format_and_transform�s ü üz/ShareableList._set_packing_format_and_transformcCsv|dkr |n||j}z.|j|j|}t | |¡|jj|¡\}Wnty^tdƒ‚Yn0|  |¡}||ƒ}|S)Nrzindex out of range) rmryrnrqr}r…rwrBr‚r‰)r4rƒr~riZback_transformrrrÚ __getitem__¦sý   zShareableList.__getitem__c Csü|dkr |n||j}z"|j|}|j|}| |¡}WntyRtdƒ‚Yn0t|ttfƒsv|jt |ƒ}|}n`|j|d|}t|tƒrœ|  t ¡n|}t |ƒ|kr´t dƒ‚|ddkrÆ|}n|jt|f}| |||¡t ||jj||¡dS)Nrzassignment index out of rangerz(bytes/str item exceeds available storagerre)rmrnryr…r‚rYrZr[r^r_rgrVr rrŠrqrxrwrB) r4rƒrOZ item_offsetr~Zcurrent_formatZ new_formatZ encoded_valueZallocated_lengthrrrÚ __setitem__·s8   ÿ ÿ  ÿýzShareableList.__setitem__cCst|j|jjd�dfS)Nr]r)rr<rwr r:rrrr=ØszShareableList.__reduce__cCst d|jjd¡dS)NrKr)rqr}rwrBr:rrrÚ__len__ÛszShareableList.__len__cCs"|jj›dt|ƒ›d|jj›d�S)Nr>z, name=r?)r<r@r|rwr r:rrrrAÞszShareableList.__repr__csd ‡fdd„tˆjƒDƒ¡S)z=The struct packing format used by all currently stored items.rfc3s|]}ˆ |¡VqdSr8)r…)rbÚir:rrrläsz'ShareableList.format..)rtÚrangermr:rr:rÚformatásÿzShareableList.formatcCsd|jdS)z>The struct packing format used for the items' storage offsets.rKr©rmr:rrrrsèsz#ShareableList._format_size_metainfocCs d|jS)z>The struct packing format used for the items' packing formats.r�r‘r:rrrruísz&ShareableList._format_packing_metainfocCs d|jS)z>The struct packing format used for the items' back transforms.r†r‘r:rrrrvòsz*ShareableList._format_back_transform_codescCs|jddS)NrrMr‘r:rrrry÷sz ShareableList._offset_data_startcCs|j|jdS)Nr)ryrnr:rrrrzýsz%ShareableList._offset_packing_formatscCs|j|jdS)NrM)rzrmr:rrrr{sz*ShareableList._offset_back_transform_codescst‡fdd„|DƒƒS)zCL.count(value) -> integer -- return number of occurrences of value.c3s|]}ˆ|kVqdSr8r)rbÚentryrNrrrlrQz&ShareableList.count..)Úsum)r4rOrrNrÚcountszShareableList.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@rFrGrHroÚfloatÚboolrZr[r<r^r`r‡Ú staticmethodr\r7r…r‰rŠr‹rŒr=r�rArIr�rsrurvryrzr{r”r–Ú classmethodÚtypesÚ GenericAliasÚ__class_getitem__rrrrr÷sTúü I!        )rHÚ__all__Ú functoolsrr(rr.rqr r›r r-rrÚO_CREATrrrr rrrVrrrrrÚs.    E