U e5dZ-ã@s,ddddddgZddlZddlZddlZddlZddlZdd lmZdd lmZdd lm Z zdd lm Z m Z Wne k rŒe d ƒ‚YnXe edƒƒ\ZZej jZGdd„deƒZ Gdd„de ƒZGdd„deƒZGdd„de ƒZGdd„de ƒZGdd„deƒZGdd„deƒZGdd„dejƒZdS)ÚLockÚRLockÚ SemaphoreÚBoundedSemaphoreÚ ConditionÚEventéNé)Úcontext)Úprocess)Úutil)ÚSemLockÚ sem_unlinkz—This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770.éc@s\eZdZe ¡Zdd„Zedd„ƒZdd„Z dd„Z d d „Z d d „Z d d„Z edd„ƒZdS)r c Csö|dkrtj ¡}| ¡}tjdkp*|dk}tdƒD]>}z t ||||  ¡|¡}|_ Wnt k rlYq4Xq|q4t dƒ‚t   d|j¡| ¡tjdkr²dd„} t  || ¡|j jdk ròdd lm} | |j jd ƒt j|tj|j jfd d dS) NÚwin32Úforkédzcannot find name for semaphorezcreated semlock with handle %scSs|j ¡dS©N)Ú_semlockÚ _after_fork)Úobj©rú3/usr/lib64/python3.8/multiprocessing/synchronize.pyrGsz%SemLock.__init__.._after_forkr)ÚregisterÚ semaphorer)Z exitpriority)r Z_default_contextZ get_contextZget_start_methodÚsysÚplatformÚrangeÚ_multiprocessingr Ú _make_namerÚFileExistsErrorr ÚdebugÚhandleÚ _make_methodsZregister_after_forkÚnameÚresource_trackerrZFinalizeÚ_cleanup) ÚselfÚkindÚvalueÚmaxvalueÚctxr#Z unlink_nowÚiÚslrrrrrÚ__init__2s8  þ    ÿzSemLock.__init__cCs"ddlm}t|ƒ||dƒdS)Nr)Ú unregisterr)r$r.r )r#r.rrrr%Ts zSemLock._cleanupcCs|jj|_|jj|_dSr)rÚacquireÚrelease©r&rrrr"Zs zSemLock._make_methodscCs |j ¡Sr)rÚ __enter__r1rrrr2^szSemLock.__enter__cGs |jj|ŽSr)rÚ__exit__©r&Úargsrrrr3aszSemLock.__exit__cCsDt |¡|j}tjdkr,t ¡ |j¡}n|j}||j|j |j fS)Nr) r Úassert_spawningrrrZget_spawning_popenZduplicate_for_childr!r'r)r#)r&r,ÚhrrrÚ __getstate__ds   zSemLock.__getstate__cCs,tjj|Ž|_t d|d¡| ¡dS)Nz recreated blocker with handle %rr)rr Z_rebuildrr r r"©r&ÚstaterrrÚ __setstate__mszSemLock.__setstate__cCsdt ¡jdttjƒfS)Nz%s-%sZ semprefix)r Úcurrent_processZ_configÚnextr Ú_randrrrrrrsÿzSemLock._make_nameN)Ú__name__Ú __module__Ú __qualname__ÚtempfileZ_RandomNameSequencer>r-Ú staticmethodr%r"r2r3r8r;rrrrrr .s"  r c@s&eZdZd dd„Zdd„Zdd„ZdS) rrcCstj|t|t|ddS©N©r*)r r-Ú SEMAPHOREÚ SEM_VALUE_MAX©r&r(r*rrrr-}szSemaphore.__init__cCs |j ¡Sr)rÚ _get_valuer1rrrÚ get_value€szSemaphore.get_valuecCs8z|j ¡}Wntk r&d}YnXd|jj|fS)NÚunknownz<%s(value=%s)>)rrIÚ ExceptionÚ __class__r?©r&r(rrrÚ__repr__ƒs  zSemaphore.__repr__N)r)r?r@rAr-rJrOrrrrr{s c@seZdZddd„Zdd„ZdS)rrcCstj|t|||ddSrD©r r-rFrHrrrr-szBoundedSemaphore.__init__cCs>z|j ¡}Wntk r&d}YnXd|jj||jjfS)NrKz<%s(value=%s, maxvalue=%s)>)rrIrLrMr?r)rNrrrrO“s ÿzBoundedSemaphore.__repr__N)r©r?r@rAr-rOrrrrrŽs c@seZdZdd„Zdd„ZdS)rcCstj|tdd|ddS©NrrErP©r&r*rrrr-¡sz Lock.__init__cCszf|j ¡r8t ¡j}t ¡jdkrd|dt ¡j7}n,|j ¡dkrLd}n|j ¡dkr`d}nd}Wnt k r~d}YnXd |j j |fS) NÚ MainThreadú|rÚNonerÚSomeOtherThreadÚSomeOtherProcessrKz<%s(owner=%s)>) rÚ_is_miner r<r#Ú threadingÚcurrent_threadrIÚ_countrLrMr?)r&r#rrrrO¤s   z Lock.__repr__NrQrrrrrŸsc@seZdZdd„Zdd„ZdS)rcCstj|tdd|ddSrR)r r-ÚRECURSIVE_MUTEXrSrrrr-ºszRLock.__init__cCs¬z||j ¡rBt ¡j}t ¡jdkr6|dt ¡j7}|j ¡}n8|j ¡dkrZd\}}n |j ¡dkrrd\}}nd\}}Wnt k r˜d\}}YnXd |j j ||fS) NrTrUr)rVrr)rWÚnonzero)rXr^)rKrKú <%s(%s, %s)>) rrYr r<r#rZr[r\rIrLrMr?)r&r#ÚcountrrrrO½s      zRLock.__repr__NrQrrrrr¸sc@sleZdZddd„Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z ddd„Z ddd„Z dd„Z ddd„Z dS)rNcCs>|p | ¡|_| d¡|_| d¡|_| d¡|_| ¡dS©Nr)rÚ_lockrÚ_sleeping_countÚ _woken_countÚ_wait_semaphorer")r&Úlockr*rrrr-Ôs    zCondition.__init__cCst |¡|j|j|j|jfSr)r r6rbrcrdrer1rrrr8Ûs  ÿzCondition.__getstate__cCs |\|_|_|_|_| ¡dSr)rbrcrdrer"r9rrrr;às ÿ zCondition.__setstate__cCs |j ¡Sr)rbr2r1rrrr2åszCondition.__enter__cGs |jj|ŽSr)rbr3r4rrrr3èszCondition.__exit__cCs|jj|_|jj|_dSr)rbr/r0r1rrrr"ës zCondition._make_methodscCsJz|jj ¡|jj ¡}Wntk r4d}YnXd|jj|j|fS)NrKr_)rcrrIrdrLrMr?rb)r&Z num_waitersrrrrOïs  ÿ zCondition.__repr__c Cs~|jj ¡stdƒ‚|j ¡|jj ¡}t|ƒD]}|j ¡q2z|j   d|¡W¢S|j ¡t|ƒD]}|j  ¡qhXdS)Nz,must acquire() condition before using wait()T) rbrrYÚAssertionErrorrcr0r\rrdr/re)r&Útimeoutr`r+rrrÚwait÷sÿ      zCondition.waitrcCs¨|jj ¡stdƒ‚|j d¡r(tdƒ‚|j d¡rN|j d¡}|s(tdƒ‚q(d}||krz|j d¡rz|j ¡|d7}qR|r¤t |ƒD]}|j ¡q†|j d¡r¤q–dS)Nzlock is not ownedFznotify: Bug in sleeping_count.acquire- res should not be Falserr) rbrrYrgrer/rdrcr0r)r&ÚnÚresZsleepersr+rrrÚnotifys$ÿÿ       zCondition.notifycCs|jtjddS)N)rj)rlrÚmaxsizer1rrrÚ notify_all(szCondition.notify_allcCsd|ƒ}|r|S|dk r$t ¡|}nd}d}|s`|dk rN|t ¡}|dkrNq`| |¡|ƒ}q,|Sra)ÚtimeÚ monotonicri)r&Z predicaterhÚresultZendtimeZwaittimerrrÚwait_for+s  zCondition.wait_for)N)N)r)N)r?r@rAr-r8r;r2r3r"rOrirlrnrrrrrrrÒs   c@s6eZdZdd„Zdd„Zdd„Zdd„Zd d d „Zd S) rcCs | | ¡¡|_| d¡|_dSra)rrÚ_condrÚ_flagrSrrrr-CszEvent.__init__c CsD|j4|j d¡r,|j ¡W5QR£dSW5QR£dSQRXdS©NFT)rsrtr/r0r1rrrÚis_setGs   z Event.is_setc Cs6|j&|j d¡|j ¡|j ¡W5QRXdS©NF)rsrtr/r0rnr1rrrÚsetNs  z Event.setc Cs"|j|j d¡W5QRXdSrw)rsrtr/r1rrrÚclearTsz Event.clearNc Csh|jX|j d¡r |j ¡n |j |¡|j d¡rP|j ¡W5QR£dSW5QR£dSQRXdSru)rsrtr/r0ri)r&rhrrrriXs     z Event.wait)N)r?r@rAr-rvrxryrirrrrrAs c@sZeZdZddd„Zdd„Zdd„Zedd „ƒZejd d „ƒZed d „ƒZ e jd d „ƒZ dS)ÚBarrierNc CsRddl}ddlm}|| d¡dƒ}| ¡}| |||||f¡d|_d|_dS)Nrr)Ú BufferWrapperr+r)ÚstructÚheapr{Zcalcsizerr;Ú_stater\) r&ZpartiesÚactionrhr*r|r{ÚwrapperZcondrrrr-js zBarrier.__init__cCs.|\|_|_|_|_|_|j ¡ d¡|_dS)Nr+)Ú_partiesÚ_actionÚ_timeoutrsÚ_wrapperZcreate_memoryviewÚcastÚ_arrayr9rrrr;ss ÿzBarrier.__setstate__cCs|j|j|j|j|jfSr)rr‚rƒrsr„r1rrrr8xs ÿzBarrier.__getstate__cCs |jdSra©r†r1rrrr~|szBarrier._statecCs||jd<dSrar‡rNrrrr~€scCs |jdS©Nrr‡r1rrrr\„szBarrier._countcCs||jd<dSrˆr‡rNrrrr\ˆs)NN) r?r@rAr-r;r8Úpropertyr~Úsetterr\rrrrrzhs    rz)Ú__all__rZrrBrroÚr r r r r Ú ImportErrorÚlistrr]rFrGÚobjectrrrrrrrzrrrrÚ s8ÿ    Mo'