U e5d@s.ddlZddlZddlZddlmZddlm Z ddl m Z m ZzddlmZWn ek rpddlmZYnXdddd d d d d dddddddddddddddgZejZejZejZejZzejZdZedWnek rdZYnXejZ z ej!Z"Wnek rdZ"YnXej#Z#[da$da%d dZ&d!dZ'eZ(d"dZ!Gd#d$d$Z)e)Z*Gd%ddZ+Gd&ddZ,Gd'dde,Z-Gd(d d Z.Gd)ddZ/Gd*dde0Z1ej2Z3e3dKd,d-Z4ea5iZ6iZ7e Z8ea9e:a;Gd.ddZm?Z@WnHek rRdd0lAmBZCdd1lmDZDeDdd2Z?d3dZ@d4da>YnXd5d6ZEGd7dde<ZFGd8d9d9e<ZGGd:d;d;e<ZHdd?ZMd@d ZNddAlmOZOeGaPdBdCZQdDd ZRzddElmSZTWn"ek rddFlUmTZTYnXdGdHZVeWedIr*ejXeVdJdS)LN) monotonic)WeakSet)islicecount)deque get_ident active_count Conditioncurrent_thread enumerate main_thread TIMEOUT_MAXEventLockRLock SemaphoreBoundedSemaphoreThreadBarrierBrokenBarrierErrorTimer ThreadError setprofilesettracelocal stack_size excepthookExceptHookArgsT get_native_idFcCs|adSN) _profile_hookfuncr#!/usr/lib64/python3.8/threading.pyr9scCs|adSr) _trace_hookr!r#r#r$rCscOstdkrt||St||Sr)_CRLock_PyRLock)argskwargsr#r#r$rQs  c@sReZdZddZddZdddZeZd d Zd d Zd dZ ddZ ddZ dS)_RLockcCst|_d|_d|_dSNr)_allocate_lock_block_owner_countselfr#r#r$__init__hsz_RLock.__init__c Cs^|j}zt|j}Wntk r(YnXd|jr:dnd|jj|jj||j t t |fS)Nz)<%s %s.%s object owner=%r count=%d at %s>lockedZunlocked) r._activenameKeyErrorr-r3 __class__ __module__ __qualname__r/hexid)r1ownerr#r#r$__repr__ms z_RLock.__repr__TcCsDt}|j|kr"|jd7_dS|j||}|r@||_d|_|SN)rr.r/r-acquire)r1blockingtimeoutmercr#r#r$rA|s z_RLock.acquirecCs<|jtkrtd|jd|_}|s8d|_|jdS)Ncannot release un-acquired lockr@)r.r RuntimeErrorr/r-release)r1rr#r#r$rHs  z_RLock.releasecCs |dSrrHr1tvtbr#r#r$__exit__sz_RLock.__exit__cCs|j|\|_|_dSr)r-rAr/r.)r1stater#r#r$_acquire_restores z_RLock._acquire_restorecCs<|jdkrtd|j}d|_|j}d|_|j||fS)NrrF)r/rGr.r-rH)r1rr<r#r#r$ _release_saves  z_RLock._release_savecCs |jtkSr)r.rr0r#r#r$ _is_ownedsz_RLock._is_ownedN)Tr>) __name__r8r9r2r=rA __enter__rHrNrPrQrRr#r#r#r$r*^s  $ r*c@speZdZdddZddZddZdd Zd d Zd d ZddZ dddZ dddZ dddZ ddZ e ZdS)r NcCs|dkrt}||_|j|_|j|_z |j|_Wntk rDYnXz |j|_Wntk rfYnXz |j|_Wntk rYnXt|_ dSr) r_lockrArHrQAttributeErrorrPrR_deque_waitersr1lockr#r#r$r2s$   zCondition.__init__cCs |jSr)rUrTr0r#r#r$rTszCondition.__enter__cGs |jj|Sr)rUrN)r1r(r#r#r$rNszCondition.__exit__cCsd|jt|jfS)Nz)rUlenrXr0r#r#r$r=szCondition.__repr__cCs|jdSr)rUrHr0r#r#r$rQszCondition._release_savecCs|jdSr)rUrA)r1xr#r#r$rPszCondition._acquire_restorecCs"|jdr|jdSdSdS)NrFT)rUrArHr0r#r#r$rRs  zCondition._is_ownedcCs|stdt}||j||}d}z>|dkrN|d}n |dkrd|d|}n |d}|WS|||sz|j|Wnt k rYnXXdS)Nzcannot wait on un-acquired lockFTr) rRrGr,rArXappendrQrPremove ValueError)r1rCwaiterZ saved_stateZgotitr#r#r$waits*   zCondition.waitcCsXd}|}|}|sT|dk rB|dkr.t|}n|t}|dkrBqT|||}q|Sr+)_timera)r1Z predicaterCendtimeZwaittimeresultr#r#r$wait_for>s   zCondition.wait_forr@c Csf|std|j}tt||}|s,dS|D]0}|z||Wq0tk r^Yq0Xq0dS)Nz!cannot notify on un-acquired lock)rRrGrXrW_islicerHr^r_)r1nZ all_waitersZwaiters_to_notifyr`r#r#r$notifyUs zCondition.notifycCs|t|jdSr)rhr[rXr0r#r#r$ notify_alllszCondition.notify_all)N)N)N)r@)rSr8r9r2rTrNr=rQrPrRrarerhriZ notifyAllr#r#r#r$r s  0   c@s4eZdZd ddZd ddZeZdd Zd d ZdS)rr@cCs&|dkrtdtt|_||_dS)Nrz$semaphore initial value must be >= 0)r_r r_cond_valuer1valuer#r#r$r2s zSemaphore.__init__TNc Cs|s|dk rtdd}d}|jf|jdkrr|s4q|dk rd|dkrPt|}n|t}|dkrdq|j|q$|jd8_d}W5QRX|S)Nz.can't specify timeout for non-blocking acquireFrr@T)r_rjrkrbra)r1rBrCrErcr#r#r$rAs$    zSemaphore.acquirec Cs.|j|jd7_|jW5QRXdSr?)rjrkrhr0r#r#r$rHszSemaphore.releasecCs |dSrrIrJr#r#r$rNszSemaphore.__exit__)r@)TN)rSr8r9r2rArTrHrNr#r#r#r$rxs   - c@seZdZdddZddZdS)rr@cCst||||_dSr)rr2_initial_valuerlr#r#r$r2s zBoundedSemaphore.__init__c CsB|j2|j|jkrtd|jd7_|jW5QRXdS)Nz!Semaphore released too many timesr@)rjrkrnr_rhr0r#r#r$rHs  zBoundedSemaphore.releaseN)r@)rSr8r9r2rHr#r#r#r$rs c@sBeZdZddZddZddZeZddZd d Zdd d Z d S)rcCstt|_d|_dSNF)r rrj_flagr0r#r#r$r2s zEvent.__init__cCs|jtdSr)rjr2rr0r#r#r$_reset_internal_locksszEvent._reset_internal_lockscCs|jSr)rpr0r#r#r$is_setsz Event.is_setc Cs&|jd|_|jW5QRXdSNT)rjrprir0r#r#r$setsz Event.setc Cs|j d|_W5QRXdSro)rjrpr0r#r#r$clearsz Event.clearNc Cs8|j(|j}|s|j|}|W5QRSQRXdSr)rjrpra)r1rCZsignaledr#r#r$ras  z Event.wait)N) rSr8r9r2rqrrZisSetrtrurar#r#r#r$rs   c@s|eZdZdddZdddZddZdd Zd d Zd d ZddZ ddZ ddZ e ddZ e ddZe ddZdS)rNcCs.tt|_||_||_||_d|_d|_dSr+)r rrj_action_timeout_parties_stater/)r1partiesactionrCr#r#r$r2Fs zBarrier.__init__c Cs|dkr|j}|jr||j}|jd7_z6|d|jkrL|n |||WW5QRS|jd8_|XW5QRXdSr?)rwrj_enterr/_exitrx_release_wait)r1rCindexr#r#r$raVs   z Barrier.waitcCs(|jdkr|jq|jdkr$tdS)Nr>r@r)ryrjrarr0r#r#r$r|ts    zBarrier._entercCs>z"|jr|d|_|jWn|YnXdSr?)rvryrjri_breakr0r#r#r$r~szBarrier._releasecs4jfdd|s"tjdkr0tdS)Ncs jdkSr+ryr#r0r#r$zBarrier._wait..r)rjrerrryr1rCr#r0r$rs  z Barrier._waitcCs(|jdkr$|jdkr$d|_|jdS)Nrr)r/ryrjrir0r#r#r$r}s  z Barrier._exitc CsT|jD|jdkr6|jdkr$d|_q<|jdkr)rjr/ryrir0r#r#r$resets   z Barrier.resetc Cs|j|W5QRXdSr)rjrr0r#r#r$abortsz Barrier.abortcCsd|_|jdSNr)ryrjrir0r#r#r$rszBarrier._breakcCs|jSr)rxr0r#r#r$rzszBarrier.partiescCs|jdkr|jSdSr+)ryr/r0r#r#r$ n_waitings zBarrier.n_waitingcCs |jdkSrrr0r#r#r$brokenszBarrier.broken)NN)N)rSr8r9r2rar|r~rr}rrrpropertyrzrrr#r#r#r$r=s       c@s eZdZdS)rN)rSr8r9r#r#r#r$rs Thread-%dcCs |tSr)_counter)templater#r#r$_newnamesrc@seZdZdZd9ddddZddZd d Zd d Zd dZddZ ddZ e rXddZ ddZ ddZddZddZd:ddZd;d!d"Zed#d$Zejd%d$Zed&d'Ze red(d)Zd*d+Zd,d-Zed.d/Zejd0d/Zd1d2Zd3d4Zd5d6Zd7d8ZdS)||_n tj|_d|_ t rXd|_ d|_ t |_d|_d|_tj|_t|_t|dS)NFT)_targetstrr_name_args_kwargs _daemonicr r_ident_HAVE_THREAD_NATIVE_ID _native_id _tstate_lockr_started _is_stopped _initialized_sysstderr_stderr_make_invoke_excepthook_invoke_excepthook _danglingadd)r1grouptargetr5r(r)rr#r#r$r2s& zThread.__init__cCs(|j|r|n d|_d|_dSrs)rrq_set_tstate_lockrr)r1is_aliver#r#r$rq(s   zThread._reset_internal_lockscCs^d}|jrd}||jr$d}|jr2|d7}|jdk rJ|d|j7}d|jj|j|fS)NinitialZstartedZstoppedz daemonz %sz <%s(%s, %s)>) rrrrrrrr7rSr)r1Zstatusr#r#r$r=4s  zThread.__repr__c Cs|jstd|jr tdt|t|<W5QRXzt|jdWn,tk rtt t|=W5QRXYnX|j dS)Nzthread.__init__() not calledz threads can only be started oncer#) rrGrrr_active_limbo_lock_limbo_start_new_thread _bootstrap Exceptionrar0r#r#r$startBs  z Thread.startcCs.z|jr|j|j|jW5|`|`|`XdSr)rrrr0r#r#r$run[s z Thread.runcCs4z |Wn"|jr(tdkr(YdSYnXdSr)_bootstrap_innerrrr0r#r#r$rls  zThread._bootstrapcCs t|_dSr)rrr0r#r#r$ _set_identszThread._set_identcCs t|_dSr)rrr0r#r#r$_set_native_idszThread._set_native_idc Cs8t|_|j|js4tt|jW5QRXdSr) _set_sentinelrrAr_shutdown_locks_lock_shutdown_locksrr0r#r#r$rs  zThread._set_tstate_lockcCsz||tr||jt|t|j <t |=W5QRXt rVt t trdt tz |Wn||YnXW5t z tt=Wn YnXW5QRXXdSr)rr4rrrrrrrtrrr%rrr rrrr0r#r#r$rs,      zThread._bootstrap_innerc Cs>|j}|dk rd|_d|_|js:tt|W5QRXdSrs)rrrrrdiscardrYr#r#r$_stopsz Thread._stopc Csttt=W5QRXdSr)rr4rr0r#r#r$_deleteszThread._deletecCsZ|jstd|js td|tkr2td|dkrD|n|jt|dddS)NThread.__init__() not calledz'cannot join thread before it is startedzcannot join current threadr)rC)rrGrrrr _wait_for_tstate_lockmaxrr#r#r$joins   z Thread.joinTr>cCs0|j}|dkrn|||r,||dSr)rrArHr)r1blockrCrZr#r#r$rs  zThread._wait_for_tstate_lockcCs|jSr)rr0r#r#r$r5s z Thread.namecCst||_dSr)rrr1r5r#r#r$r5scCs|jSr)rr0r#r#r$idents z Thread.identcCs|jSr)rr0r#r#r$ native_id$s zThread.native_idcCs&|js|jsdS|d|j Sro)rrrrrr0r#r#r$r/s  zThread.is_alivecCs ddl}|jdtdd|S)Nrz/isAlive() is deprecated, use is_alive() instead) stacklevel)warningswarnDeprecationWarningr)r1rr#r#r$isAlive=s zThread.isAlivecCs|jSr)rr0r#r#r$rGs z Thread.daemoncCs*|jstd|jr td||_dS)Nrz)cannot set daemon status of active thread)rrGrrrrr1Zdaemonicr#r#r$rVs  cCs|jSrrr0r#r#r$isDaemon^szThread.isDaemoncCs ||_dSrrrr#r#r$ setDaemonaszThread.setDaemoncCs|jSrr5r0r#r#r$getNamedszThread.getNamecCs ||_dSrrrr#r#r$setNamegszThread.setName)NNNr#N)N)Tr>)rSr8r9rr2rqr=rrrrrrrrrrrrrr5setterrrrrrrrrrr#r#r#r$rsP  /   &        ) _excepthook_ExceptHookArgs)print_exception) namedtuplez'exc_type exc_value exc_traceback threadcCst|Sr)r)r(r#r#r$rwscCs|jtkrdStdk r(tjdk r(tj}n$|jdk rH|jj}|dkrLdSndS|jdk r`|jj}nt}td|d|ddt |j|j |j |d| dS)NzException in thread :Tfileflush)r) exc_type SystemExitrrthreadrr5rprint_print_exception exc_value exc_tracebackr)r(rr5r#r#r$rzs(     csPttjdkrtddkr*tdtjttfdd}|S)Nzthreading.excepthook is Nonezsys.excepthook is Nonec szz,t}|dkr}t|f}||Wntk r}zbd|_~dk rbjdk rbj}n|j}d|dddk rjdk rj}n}|W5d}~XYnXW5d}XdS)NTz"Exception in threading.excepthook:r)rrr__suppress_context__rr)rr(hookexcrZsys_excepthookZ local_printZ local_sysZold_excepthookZold_sys_excepthookZ sys_exc_infor#r$invoke_excepthooks*  z2_make_invoke_excepthook..invoke_excepthook)rrrGexc_infor)rr#rr$rs rc@s&eZdZdddZddZddZdS) rNcCsFt|||_||_|dk r"|ng|_|dk r4|ni|_t|_dSr)rr2intervalfunctionr(r)rfinished)r1rrr(r)r#r#r$r2s  zTimer.__init__cCs|jdSr)rrtr0r#r#r$cancelsz Timer.cancelcCs6|j|j|js(|j|j|j|jdSr)rrarrrrr(r)rtr0r#r#r$rs z Timer.run)NN)rSr8r9r2rrr#r#r#r$rs c@seZdZddZdS) _MainThreadc CsTtj|ddd||j|tr6|t|t |j <W5QRXdS)NZ MainThreadFr5r) rr2rrrtrrrrr4rr0r#r#r$r2s z_MainThread.__init__N)rSr8r9r2r#r#r#r$rsrc@s.eZdZddZddZddZd dd ZdS) _DummyThreadc CsPtj|tddd|j|tr2|t|t |j <W5QRXdS)NzDummy-%dTr) rr2rrrtrrrrr4rr0r#r#r$r2s z_DummyThread.__init__cCsdSrr#r0r#r#r$r sz_DummyThread._stopcCsdSrsr#r0r#r#r$rsz_DummyThread.is_aliveNcCsdSrr#rr#r#r$rsz_DummyThread.join)N)rSr8r9r2rrrr#r#r#r$rs rcCs,z ttWStk r&tYSXdSr)r4rr6rr#r#r#r$r s c Cs,tttttW5QRSQRXdSr)rr[r4rr#r#r#r$r(scCsttttSr)listr4valuesrr#r#r#r$ _enumerate4src Cs4t&ttttW5QRSQRXdSr)rrr4rrr#r#r#r$r 8s)rc Csftjr dStj}|tttt}tW5QRX|sFqb|D]}| |qJq dSr) _main_threadrrrHrrrrrurA)ZtlockZlocksrZr#r#r$ _shutdownKs rcCstSr)rr#r#r#r$r ss)_local)rc Cstai}ztt}Wntk r2t}YnX|atata txtt }| t |D]>}||kr| dt}||_|||<qb| d|qbttt |W5QRXdS)NTF)r,rr4rr6rrrrtrrupdaterrqrrrru)Z new_activeZcurrentZthreadsrrr#r#r$ _after_forks0        rregister_at_fork)Zafter_in_child)r)Yos_ossysr_threadtimerrbZ _weakrefsetr itertoolsrrfrr/ _collectionsrrW ImportError collections__all__start_new_threadr allocate_lockr,rrrrr]rVerrorrrr&r r r%rrrr*r'r rrrrrGr__next__rrrr4rrrrtrrrrrr tracebackrrrrrrrr Z currentThreadrZ activeCountrr rrrr rrZ_threading_localrhasattrrr#r#r#r$s         q'P&O   5   ( 5