3 \/ @s,ddddddgZddlZddlZddlZddlZddlZdd lmZdd lmZdd lm Z ydd lm Z m Z Wne k re dYnXe ed\ZZej jZGdddeZ Gddde ZGdddeZGddde ZGddde ZGdddeZGdddeZGdddejZdS)LockRLock SemaphoreBoundedSemaphore ConditionEventN)context)process)util)SemLock sem_unlinkz*This platform lacks a functioning sem_openz( implementation, therefore, the requiredz+ synchronization primitives needed will notz function, see issue 3770.c@s\eZdZejZddZeddZddZ ddZ d d Z d d Z d dZ eddZdS)r c Cs|dkrtjj}|j}tjdkp*|dk}xPtdD]<}y tj||||j |}|_ Wnt k rnYq6XPq6Wt dt j d|j|jtjdkrdd} t j|| |j jdk rdd lm} | |j jt j|tj|j jfd d dS) Nwin32forkdzcannot find name for semaphorezcreated semlock with handle %scSs|jjdS)N)_semlock _after_fork)objr3/usr/lib64/python3.6/multiprocessing/synchronize.pyrGsz%SemLock.__init__.._after_forkr)registerr)Z exitpriority)r Z_default_contextZ get_contextZget_start_methodsysplatformrange_multiprocessingr _make_namerFileExistsErrorr debughandle _make_methodsZregister_after_forknamesemaphore_trackerrZFinalize_cleanup) selfkindvaluemaxvaluectxr!Z unlink_nowislrrrrr__init__2s.       zSemLock.__init__cCs ddlm}t|||dS)Nr) unregister)r"r,r )r!r,rrrr#Ts zSemLock._cleanupcCs|jj|_|jj|_dS)N)racquirerelease)r$rrrr Zs zSemLock._make_methodscCs |jjS)N)r __enter__)r$rrrr/^szSemLock.__enter__cGs |jj|S)N)r__exit__)r$argsrrrr0aszSemLock.__exit__cCsDtj||j}tjdkr,tjj|j}n|j}||j|j |j fS)Nr) r assert_spawningrrrZget_spawning_popenZduplicate_for_childrr%r'r!)r$r*hrrr __getstate__ds   zSemLock.__getstate__cCs,tjj||_tjd|d|jdS)Nz recreated blocker with handle %rr)rr Z_rebuildrr rr )r$staterrr __setstate__mszSemLock.__setstate__cCsdtjjdttjfS)Nz%s-%sZ semprefix)r current_processZ_confignextr _randrrrrrrszSemLock._make_nameN)__name__ __module__ __qualname__tempfileZ_RandomNameSequencer9r+ staticmethodr#r r/r0r4r6rrrrrr .s"  r c@s&eZdZd ddZddZddZdS) rrcCstj|t|t|ddS)N)r()r r+ SEMAPHORE SEM_VALUE_MAX)r$r&r(rrrr+}szSemaphore.__init__cCs |jjS)N)r _get_value)r$rrr get_valueszSemaphore.get_valuec Cs8y|jj}Wntk r&d}YnXd|jj|fS)Nunknownz<%s(value=%s)>)rrA Exception __class__r:)r$r&rrr__repr__s  zSemaphore.__repr__N)r)r:r;r<r+rBrFrrrrr{s c@seZdZdddZddZdS)rrcCstj|t|||ddS)N)r()r r+r?)r$r&r(rrrr+szBoundedSemaphore.__init__c Cs>y|jj}Wntk r&d}YnXd|jj||jjfS)NrCz<%s(value=%s, maxvalue=%s)>)rrArDrEr:r')r$r&rrrrFs  zBoundedSemaphore.__repr__N)r)r:r;r<r+rFrrrrrs c@seZdZddZddZdS)rcCstj|tdd|ddS)Nr)r()r r+r?)r$r(rrrr+sz Lock.__init__c Csyf|jjr8tjj}tjjdkrd|dtjj7}n,|jjdkrLd}n|jjdkr`d}nd}Wnt k r~d}YnXd |j j |fS) N MainThread|rNonerSomeOtherThreadSomeOtherProcessrCz<%s(owner=%s)>) r_is_miner r7r! threadingcurrent_threadrA_countrDrEr:)r$r!rrrrFs   z Lock.__repr__N)r:r;r<r+rFrrrrrsc@seZdZddZddZdS)rcCstj|tdd|ddS)Nr)r()r r+RECURSIVE_MUTEX)r$r(rrrr+szRLock.__init__c Csy||jjrBtjj}tjjdkr6|dtjj7}|jj}n8|jjdkrZd \}}n |jjdkrrd \}}nd \}}Wnt k rd\}}YnXd |j j ||fS)NrGrHrrIrrJnonzerorKrCz <%s(%s, %s)>)rIr)rJrQ)rKrQ)rCrC) rrLr r7r!rMrNrOrArDrEr:)r$r!countrrrrFs      zRLock.__repr__N)r:r;r<r+rFrrrrrsc@sjeZdZdddZddZddZdd Zd d Zd d ZddZ dddZ ddZ ddZ dddZ dS)rNcCs>|p |j|_|jd|_|jd|_|jd|_|jdS)Nr)r_lockr_sleeping_count _woken_count_wait_semaphorer )r$lockr(rrrr+s    zCondition.__init__cCstj||j|j|j|jfS)N)r r2rSrTrUrV)r$rrrr4s zCondition.__getstate__cCs |\|_|_|_|_|jdS)N)rSrTrUrVr )r$r5rrrr6szCondition.__setstate__cCs |jjS)N)rSr/)r$rrrr/szCondition.__enter__cGs |jj|S)N)rSr0)r$r1rrrr0szCondition.__exit__cCs|jj|_|jj|_dS)N)rSr-r.)r$rrrr s zCondition._make_methodsc CsJy|jjj|jjj}Wntk r4d}YnXd|jj|j|fS)NrCz <%s(%s, %s)>)rTrrArUrDrEr:rS)r$Z num_waitersrrrrFs   zCondition.__repr__c Cs|jjjstd|jj|jjj}xt|D]}|jjq4Wz|jj d|S|j jxt|D]}|jj qjWXdS)Nz,must acquire() condition before using wait()T) rSrrLAssertionErrorrTr.rOrrVr-rU)r$timeoutrRr)rrrwaits   zCondition.waitcCs||jjjstd|jjd s&tx$|jjdrJ|jjd}|s(tq(W|jjdrx|jj|jj|jjddS)Nzlock is not ownedF) rSrrLrXrVr-rUrTr.)r$resrrrnotifys     zCondition.notifycCs|jjjstd|jjd s&tx$|jjdrJ|jjd}|s(tq(Wd}x"|jjdrr|jj|d7}qRW|rxt |D]}|jjqWx|jjdrqWdS)Nzlock is not ownedFrr) rSrrLrXrVr-rUrTr.r)r$r[Zsleepersr)rrr notify_alls    zCondition.notify_allcCsh|}|r|S|dk r$tj|}nd}d}x6|sb|dk rP|tj}|dkrPP|j||}q.W|S)Nr)timeZ monotonicrZ)r$Z predicaterYresultZendtimeZwaittimerrrwait_for6s   zCondition.wait_for)N)N)N)r:r;r<r+r4r6r/r0r rFrZr\r]r`rrrrrs  c@s6eZdZddZddZddZddZd d d Zd S) rcCs |j|j|_|jd|_dS)Nr)rr_condr_flag)r$r(rrrr+NszEvent.__init__c Cs0|j |jjdr"|jjdSdSQRXdS)NFT)rarbr-r.)r$rrris_setRs   z Event.is_setc Cs6|j&|jjd|jj|jjWdQRXdS)NF)rarbr-r.r])r$rrrsetYs  z Event.setc Cs"|j|jjdWdQRXdS)NF)rarbr-)r$rrrclear_sz Event.clearNc CsT|jD|jjdr |jjn |jj||jjdrF|jjdSdSQRXdS)NFT)rarbr-r.rZ)r$rYrrrrZcs     z Event.wait)N)r:r;r<r+rcrdrerZrrrrrLs c@sZeZdZdddZddZddZedd Zejd d Zed d Z e jd d Z dS)BarrierNc CsRddl}ddlm}||jdd}|j}|j|||||fd|_d|_dS)Nrr) BufferWrapperr)r)structheaprgZcalcsizerr6_staterO) r$ZpartiesactionrYr(rhrgwrapperZcondrrrr+us zBarrier.__init__cCs.|\|_|_|_|_|_|jjjd|_dS)Nr))_parties_action_timeoutra_wrapperZcreate_memoryviewcast_array)r$r5rrrr6~szBarrier.__setstate__cCs|j|j|j|j|jfS)N)rmrnrorarp)r$rrrr4s zBarrier.__getstate__cCs |jdS)Nr)rr)r$rrrrjszBarrier._statecCs||jd<dS)Nr)rr)r$r&rrrrjscCs |jdS)Nr)rr)r$rrrrOszBarrier._countcCs||jd<dS)Nr)rr)r$r&rrrrOs)NN) r:r;r<r+r6r4propertyrjsetterrOrrrrrfss   rfzRThis platform lacks a functioning sem_open implementation, therefore, the requiredz}This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will notzThis platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770.)__all__rMrr=rr^r r r r r ImportErrorlistrrPr?r@objectrrrrrrrfrrrr s0    Mz'