U e5dZ-@s,ddddddgZddlZddlZddlZddlZddlZdd lmZdd lmZdd lm Z zdd lm Z m Z Wne k re d YnXe ed\ZZej jZGdddeZ Gddde ZGdddeZGddde ZGddde ZGdddeZGdddeZGdddejZdS)LockRLock SemaphoreBoundedSemaphore ConditionEventN)context)process)util)SemLock sem_unlinkzThis platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770.c@s\eZdZeZddZeddZddZ ddZ d d Z d d Z d dZ eddZdS)r c Cs|dkrtj}|}tjdkp*|dk}tdD]>}z t|||| |}|_ Wnt k rlYq4Xq|q4t dt d|j|tjdkrdd} t || |j jdk rdd lm} | |j jd t j|tj|j jfd d dS) Nwin32forkdzcannot find name for semaphorezcreated semlock with handle %scSs|jdSN)_semlock _after_fork)objr3/usr/lib64/python3.8/multiprocessing/synchronize.pyrGsz%SemLock.__init__.._after_forkr)register semaphorer)Z exitpriority)r Z_default_contextZ get_contextZget_start_methodsysplatformrange_multiprocessingr _make_namerFileExistsErrorr debughandle _make_methodsZregister_after_forknameresource_trackerrZFinalize_cleanup) selfkindvaluemaxvaluectxr#Z unlink_nowislrrrrr__init__2s8      zSemLock.__init__cCs"ddlm}t|||ddS)Nr) unregisterr)r$r.r )r#r.rrrr%Ts zSemLock._cleanupcCs|jj|_|jj|_dSr)racquirereleaser&rrrr"Zs zSemLock._make_methodscCs |jSr)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||_td|d|dS)Nz recreated blocker with handle %rr)rr Z_rebuildrr r r"r&staterrr __setstate__mszSemLock.__setstate__cCsdtjdttjfS)Nz%s-%sZ semprefix)r current_processZ_confignextr _randrrrrrrszSemLock._make_nameN)__name__ __module__ __qualname__tempfileZ_RandomNameSequencer>r- staticmethodr%r"r2r3r8r;rrrrrr .s"  r c@s&eZdZd ddZddZddZdS) rrcCstj|t|t|ddSNr*)r r- SEMAPHORE SEM_VALUE_MAXr&r(r*rrrr-}szSemaphore.__init__cCs |jSr)r _get_valuer1rrr get_valueszSemaphore.get_valuecCs8z|j}Wntk r&d}YnXd|jj|fS)Nunknownz<%s(value=%s)>)rrI Exception __class__r?r&r(rrr__repr__s  zSemaphore.__repr__N)r)r?r@rAr-rJrOrrrrr{s c@seZdZdddZddZdS)rrcCstj|t|||ddSrDr r-rFrHrrrr-szBoundedSemaphore.__init__cCs>z|j}Wntk r&d}YnXd|jj||jjfS)NrKz<%s(value=%s, maxvalue=%s)>)rrIrLrMr?r)rNrrrrOs zBoundedSemaphore.__repr__N)rr?r@rAr-rOrrrrrs c@seZdZddZddZdS)rcCstj|tdd|ddSNrrErPr&r*rrrr-sz Lock.__init__cCszf|jr8tj}tjdkrd|dtj7}n,|jdkrLd}n|jdkr`d}nd}Wnt k r~d}YnXd |j j |fS) N MainThread|rNonerSomeOtherThreadSomeOtherProcessrKz<%s(owner=%s)>) r_is_miner r<r# threadingcurrent_threadrI_countrLrMr?)r&r#rrrrOs   z Lock.__repr__NrQrrrrrsc@seZdZddZddZdS)rcCstj|tdd|ddSrR)r r-RECURSIVE_MUTEXrSrrrr-szRLock.__init__cCsz||jrBtj}tjdkr6|dtj7}|j}n8|jdkrZd\}}n |jdkrrd\}}nd\}}Wnt k rd\}}YnXd |j j ||fS) NrTrUr)rVrr)rWnonzero)rXr^)rKrK <%s(%s, %s)>) rrYr r<r#rZr[r\rIrLrMr?)r&r#countrrrrOs      zRLock.__repr__NrQrrrrrsc@sleZdZdddZddZddZdd Zd d Zd d ZddZ dddZ dddZ ddZ dddZ dS)rNcCs>|p ||_|d|_|d|_|d|_|dSNr)r_lockr_sleeping_count _woken_count_wait_semaphorer")r&lockr*rrrr-s    zCondition.__init__cCst||j|j|j|jfSr)r r6rbrcrdrer1rrrr8s  zCondition.__getstate__cCs |\|_|_|_|_|dSr)rbrcrdrer"r9rrrr;s  zCondition.__setstate__cCs |jSr)rbr2r1rrrr2szCondition.__enter__cGs |jj|Sr)rbr3r4rrrr3szCondition.__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_waitersrrrrOs   zCondition.__repr__c Csj|j|jj}t|D]}|jqz|jd|WS|jt|D]}|jqTXdS)NT) rcr0rbrr\rrdr/re)r&timeoutr`r+rrrwaits      zCondition.waitrcCst|jdr|jd}qd}||krF|jdrF|j|d7}q|rpt|D]}|jqR|jdrpqbdS)NFrr)rdr/rcrer0r)r&nresZsleepersr+rrrnotifys       zCondition.notifycCs|jtjddS)N)ri)rkrmaxsizer1rrr notify_all(szCondition.notify_allcCsd|}|r|S|dk r$t|}nd}d}|s`|dk rN|t}|dkrNq`|||}q,|Sra)time monotonicrh)r&Z predicatergresultZendtimeZwaittimerrrwait_for+s  zCondition.wait_for)N)N)r)N)r?r@rAr-r8r;r2r3r"rOrhrkrmrqrrrrrs   c@s6eZdZddZddZddZddZd d d Zd S) rcCs |||_|d|_dSra)rr_condr_flagrSrrrr-CszEvent.__init__c CsD|j4|jdr,|jW5QRdSW5QRdSQRXdSNFT)rrrsr/r0r1rrris_setGs   z Event.is_setc Cs6|j&|jd|j|jW5QRXdSNF)rrrsr/r0rmr1rrrsetNs  z Event.setc Cs"|j|jdW5QRXdSrv)rrrsr/r1rrrclearTsz Event.clearNc Csh|jX|jdr |jn |j||jdrP|jW5QRdSW5QRdSQRXdSrt)rrrsr/r0rh)r&rgrrrrhXs     z Event.wait)N)r?r@rAr-rurwrxrhrrrrrAs c@sZeZdZdddZddZddZedd Zejd d Zed d Z e jd d Z dS)BarrierNc CsRddl}ddlm}||dd}|}||||||fd|_d|_dS)Nrr) BufferWrapperr+r)structheaprzZcalcsizerr;_stater\) r&Zpartiesactionrgr*r{rzwrapperZcondrrrr-js zBarrier.__init__cCs.|\|_|_|_|_|_|jd|_dS)Nr+)_parties_action_timeoutrr_wrapperZcreate_memoryviewcast_arrayr9rrrr;ss zBarrier.__setstate__cCs|j|j|j|j|jfSr)rrrrrrr1rrrr8xs zBarrier.__getstate__cCs |jdSrarr1rrrr}|szBarrier._statecCs||jd<dSrarrNrrrr}scCs |jdSNrrr1rrrr\szBarrier._countcCs||jd<dSrrrNrrrr\s)NN) r?r@rAr-r;r8propertyr}setterr\rrrrryhs    ry)__all__rZrrBrrnr r r r r ImportErrorlistrr]rFrGobjectrrrrrrryrrrr s8    Mo'