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 Csn|jj|jjj}xt|D]}|jjq Wz|jjd|S|jjxt|D]}|jjqVWXdS)NT) rTr.rSrrOrrVr-rU)r$timeoutrRr)rrrwaits   zCondition.waitcCsNx|jjdr|jjd}qW|jjdrJ|jj|jj|jjddS)NF)rUr-rTrVr.)r$resrrrnotifys    zCondition.notifycCs|x|jjdr|jjd}qWd}x"|jjdrD|jj|d7}q$W|rxxt|D]}|jjqTWx|jjdrvqhWdS)NFrr)rUr-rTrVr.r)r$rZZsleepersr)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 monotonicrY)r$Z predicaterXresultZendtimeZwaittimerrrwait_for6s   zCondition.wait_for)N)N)N)r:r;r<r+r4r6r/r0r rFrYr[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)r`rar-r.)r$rrris_setRs   z Event.is_setc Cs6|j&|jjd|jj|jjWdQRXdS)NF)r`rar-r.r\)r$rrrsetYs  z Event.setc Cs"|j|jjdWdQRXdS)NF)r`rar-)r$rrrclear_sz Event.clearNc CsT|jD|jjdr |jjn |jj||jjdrF|jjdSdSQRXdS)NFT)r`rar-r.rY)r$rXrrrrYcs     z Event.wait)N)r:r;r<r+rbrcrdrYrrrrrLs c@sZeZdZdddZddZddZedd Zejd d Zed d Z e jd d Z dS)BarrierNc CsRddl}ddlm}||jdd}|j}|j|||||fd|_d|_dS)Nrr) BufferWrapperr)r)structheaprfZcalcsizerr6_staterO) r$ZpartiesactionrXr(rgrfwrapperZcondrrrr+us zBarrier.__init__cCs.|\|_|_|_|_|_|jjjd|_dS)Nr))_parties_action_timeoutr`_wrapperZcreate_memoryviewcast_array)r$r5rrrr6~szBarrier.__setstate__cCs|j|j|j|j|jfS)N)rlrmrnr`ro)r$rrrr4s zBarrier.__getstate__cCs |jdS)Nr)rq)r$rrrriszBarrier._statecCs||jd<dS)Nr)rq)r$r&rrrriscCs |jdS)Nr)rq)r$rrrrOszBarrier._countcCs||jd<dS)Nr)rq)r$r&rrrrOs)NN) r:r;r<r+r6r4propertyrisetterrOrrrrress   rezRThis 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@objectrrrrrrrerrrr s0    Mz'