a Z^@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)(N)heap) get_context) reductionassert_spawning)RawValueRawArrayValueArraycopy synchronized)cubBhHiIlLqQfdcCs t|}t|}t||dSN)ctypessizeofr BufferWrapper rebuild_ctype)type_sizewrapperr#4/usr/lib64/python3.9/multiprocessing/sharedctypes.py _new_value's  r%cGs<t||}t|}tt|dt||j||S)z> Returns a ctypes object allocated from shared memory r)typecode_to_typegetr%rmemset addressofr__init__)typecode_or_typeargsr objr#r#r$r,s   rcCsjt||}t|trD||}t|}tt|dt||S|t |}t|}|j ||SdS)z= Returns a ctypes array allocated from shared memory rN) r&r' isinstanceintr%rr(r)rlenr*)r+size_or_initializerr r-resultr#r#r$r6s    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'r4)rrRLockhasattrAttributeErrorr )r+r3r4r,r-r#r#r$r Fs   r cCsTt||}|dur|S|dvr0|p&t}|}t|dsFtd|t|||dS)z9 Return a synchronization wrapper for a RawArray Fr5r6r7r8)rrr9r:r;r )r+r1r3r4r-r#r#r$r Ts    r cCstt|}|t|d<|S)Nr)r%typerZpointer)r-Znew_objr#r#r$r 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#).0Zfieldr#r#r$ vz synchronized..cSsi|]}|t|qSr#) make_property)r=namer#r#r$ wr?z synchronized.. Synchronized)r.SynchronizedBaserrZ _SimpleCDatarCr _type_c_charSynchronizedStringSynchronizedArrayr< class_cacheKeyErrorZ_fields___name__)r-r3r4clsZsclsnamesrZ classnamer#r#r$r gs"          r cCs@t|t|tjr(t|j|j|jffStt||jdffSdSr) rr.rr rrE_wrapperZ_length_r<)r-r#r#r$ reduce_ctypes rOcCs8|dur||}t|t|}||}||_|Sr)_ForkingPicklerregisterrOcreate_memoryviewZ from_bufferrN)r r"lengthbufr-r#r#r$rs  rcCsNz t|WStyHi}tt|fd|||t|<||YS0dS)N) prop_cacherJexectemplate)rArr#r#r$r@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)rDNcCsB||_|r||_n|ptdd}||_|jj|_|jj|_dS)NT)force)_obj_lockrr9r6release)selfr-r3r4r#r#r$r*s  zSynchronizedBase.__init__cCs |jSr)r[ __enter__r]r#r#r$r^szSynchronizedBase.__enter__cGs |jj|Sr)r[__exit__)r]r,r#r#r$r`szSynchronizedBase.__exit__cCst|t|j|jffSr)rr rZr[r_r#r#r$ __reduce__szSynchronizedBase.__reduce__cCs|jSrrZr_r#r#r$get_objszSynchronizedBase.get_objcCs|jSr)r[r_r#r#r$get_lockszSynchronizedBase.get_lockcCsdt|j|jfS)Nz<%s wrapper for %s>)r<rKrZr_r#r#r$__repr__szSynchronizedBase.__repr__)NN) rK __module__ __qualname__r*r^r`rarcrdrer#r#r#r$rDs rDc@seZdZedZdS)rCvalueN)rKrfrgr@rhr#r#r#r$rCsrCc@s4eZdZddZddZddZddZd d Zd S) rHcCs t|jSr)r0rZr_r#r#r$__len__szSynchronizedArray.__len__cCs2||j|WdS1s$0YdSrrb)r]rr#r#r$ __getitem__szSynchronizedArray.__getitem__cCs2|||j|<Wdn1s$0YdSrrb)r]rrhr#r#r$ __setitem__szSynchronizedArray.__setitem__cCs6||j||WdS1s(0YdSrrb)r]startstopr#r#r$ __getslice__szSynchronizedArray.__getslice__cCs6|||j||<Wdn1s(0YdSrrb)r]rlrmvaluesr#r#r$ __setslice__szSynchronizedArray.__setslice__N)rKrfrgrirjrkrnrpr#r#r#r$rHs rHc@seZdZedZedZdS)rGrhrawN)rKrfrgr@rhrqr#r#r#r$rGsrG)NN)-rweakrefrrcontextrrForkingPicklerrP__all__rFZc_wcharZc_byteZc_ubyteZc_shortZc_ushortZc_intZc_uintZc_longZc_ulongZ c_longlongZ c_ulonglongZc_floatZc_doubler&r%rrr r r r rOrr@rXrVWeakKeyDictionaryrIobjectrDrCrHrGr#r#r#r$ s>