a Z^c@s:ddlZddlZddlmZddlmZddlmZmZejZ gdZ ej ej ej ejejejejejejejejejejejdZdd Zd d Zd d ZdddddZdddddZddZd'ddZ ddZ!ddZ"ddZ#dZ$iZ%e&Z'Gdd d e(Z)Gd!d"d"e)Z*Gd#d$d$e)Z+Gd%d&d&e+Z,dS)(Ni)heap) get_context) reductionassert_spawning)RawValueRawArrayValueArraycopy synchronized)ZcZuZbZBZhZHiZIZlZLZqZQZfdcCs t|}t|}t||dSN)ctypessizeofrZ BufferWrapper rebuild_ctype)type_Zsizewrapperr4/usr/lib64/python3.9/multiprocessing/sharedctypes.py _new_value's  rcGs<t||}t|}tt|dt||j||S)z> Returns a ctypes object allocated from shared memory r)typecode_to_typegetrrmemset addressofr__init__)typecode_or_typeargsrobjrrrr,s   rcCsjt||}t|trD||}t|}tt|dt||S|t |}t|}|j ||SdS)z= Returns a ctypes array allocated from shared memory rN) rr isinstanceZintrrrrrlenr)rsize_or_initializerrrZresultrrrr6s    rT)lockctxcGsZt|g|R}|dur|S|dvr6|p,t}|}t|dsLtd|t|||dS)z6 Return a synchronization wrapper for a Value FTNacquire%r has no method 'acquire'r")rrRLockhasattrAttributeErrorr )rr!r"rrrrrrFs   rcCsTt||}|dur|S|dvr0|p&t}|}t|dsFtd|t|||dS)z9 Return a synchronization wrapper for a RawArray Fr#r$r%r&)rrr'r(r)r )rr r!r"rrrrrTs    rcCstt|}|t|d<|S)Nr)rtyperZpointer)rZnew_objrrrr bs r cCst|trJd|pt}t|tjr4t|||St|tjrd|jtjurXt |||St |||St |}z t |}WnPt ydd|jD}dd|D}d|j}t |tf|}t |<Yn0||||SdS)Nzobject already synchronizedcSsg|] }|dqS)rr).0ZfieldrrrZ vz synchronized..cSsi|]}|t|qSr) make_property)r+namerrrZ wr,z synchronized.. Synchronized)rSynchronizedBaserrZ _SimpleCDatar/r_type_c_charSynchronizedStringSynchronizedArrayr* class_cacheKeyErrorZ_fields___name__)rr!r"ZclsZsclsZnamesr Z classnamerrrr gs"          r cCs@t|t|tjr(t|j|j|jffStt||jdffSdSr ) rrrrrr1_wrapperZ_length_r*)rrrr reduce_ctypes r9cCs8|dur||}t|t|}||}||_|Sr )_ForkingPicklerZregisterr9Zcreate_memoryviewZ from_bufferr8)rrZlengthZbufrrrrrs  rcCsNz t|WStyHi}tt|fd|||t|<||YS0dS)Ni) prop_cacher6Zexectemplate)r.r rrrr-s   r-z def get%s(self): self.acquire() try: return self._obj.%s finally: self.release() def set%s(self, value): self.acquire() try: self._obj.%s = value finally: self.release() %s = property(get%s, set%s) c@sFeZdZdddZddZddZdd Zd d Zd d ZddZ dS)r0NcCsB||_|r||_n|ptdd}||_|jj|_|jj|_dS)NT)Zforce)_obj_lockrr'r$Zrelease)selfrr!r"rrrrs  zSynchronizedBase.__init__cCs |jSr )r> __enter__r?rrrr@zSynchronizedBase.__enter__cGs |jj|Sr )r>__exit__)r?rrrrrCrBzSynchronizedBase.__exit__cCst|t|j|jffSr )rr r=r>rArrr __reduce__szSynchronizedBase.__reduce__cC|jSr r=rArrrget_objrBzSynchronizedBase.get_objcCrEr )r>rArrrget_lockrBzSynchronizedBase.get_lockcCsdt|j|jfS)Nz<%s wrapper for %s>)r*r7r=rArrr__repr__rBzSynchronizedBase.__repr__NN) r7 __module__ __qualname__rr@rCrDrGrHrIrrrrr0s r0c@seZdZedZdS)r/valueN)r7rKrLr-rMrrrrr/sr/c@s4eZdZddZddZddZddZd d Zd S) r4cCs t|jSr )rr=rArrr__len__rBzSynchronizedArray.__len__cCs2||j|WdS1s$0YdSr rF)r?r rrr __getitem__zSynchronizedArray.__getitem__cCs2|||j|<Wdn1s$0YdSr rF)r?r rMrrr __setitem__rPzSynchronizedArray.__setitem__cCs6||j||WdS1s(0YdSr rF)r?startstoprrr __getslice__rPzSynchronizedArray.__getslice__cCs6|||j||<Wdn1s(0YdSr rF)r?rRrSZvaluesrrr __setslice__rPzSynchronizedArray.__setslice__N)r7rKrLrNrOrQrTrUrrrrr4s r4c@seZdZedZedZdS)r3rMrawN)r7rKrLr-rMrVrrrrr3sr3rJ)-rZweakrefZrrZcontextrrZForkingPicklerr:Z__all__r2Zc_wcharZc_byteZc_ubyteZc_shortZc_ushortZc_intZc_uintZc_longZc_ulongZ c_longlongZ c_ulonglongZc_floatZc_doublerrrrrrr r r9rr-r<r;ZWeakKeyDictionaryr5Zobjectr0r/r4r3rrrrZ s>