grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026U iÛf„Æã@s2dZddlZddlZddlZddlmZddl m Z ddl m Z mZzddlmZWn ek rtddlmZYnXddd d d d d ddddddddddddddddgZejZejZejZejZzejZdZe d¡Wnek rðd ZYnXej Z!z ej"Z#Wnek �rdZ#YnXej$Z$[da%da&d!d„Z'd"d„Z(eZ)d#d„Z"Gd$d%„d%ƒZ*e*Z+Gd&d „d ƒZ,Gd'd„dƒZ-Gd(d„de-ƒZ.Gd)d„dƒZ/Gd*d„dƒZ0Gd+d„de1ƒZ2eƒj3Z4e4ƒdLd-d.„Z5eƒa6iZ7iZ8e ƒZ9eƒa:e;ƒaa?m@ZAWnHek �rVdd1lBmCZDdd2lmEZEeEdd3ƒZ@d4d„ZAd5d„a?YnXd6d7„ZFGd8d„de=ƒZGGd9d:„d:e=ƒZHGd;d<„dd„ZLeLZMd?d@„ZNdAd „ZOddBlmPZPeHƒaQdCdD„ZRdEd „ZSzddFlmTZUWn"ek �r ddGlVmUZUYnXdHdI„ZWeXedJƒ�r.ejYeWdK�dS)Mz;Thread module emulating a subset of Java's threading model.éN)Ú monotonic)ÚWeakSet)ÚisliceÚcount)ÚdequeÚ get_identÚ active_countÚ ConditionÚcurrent_threadÚ enumerateÚ main_threadÚ TIMEOUT_MAXÚEventÚLockÚRLockÚ SemaphoreÚBoundedSemaphoreÚThreadÚBarrierÚBrokenBarrierErrorÚTimerÚ ThreadErrorÚ setprofileÚsettraceÚlocalÚ stack_sizeÚ excepthookÚExceptHookArgsTÚ get_native_idFcCs|adS)z¸Set a profile function for all threads started from the threading module. The func will be passed to sys.setprofile() for each thread, before its run() method is called. N)Ú _profile_hook©Úfunc©r"ú./opt/alt/python38/lib64/python3.8/threading.pyr9scCs|adS)z´Set a trace function for all threads started from the threading module. The func will be passed to sys.settrace() for each thread, before its run() method is called. N)Ú _trace_hookr r"r"r#rCscOstdkrt||ŽSt||ŽS)a2Factory function that returns a new reentrant lock. A reentrant lock must be released by the thread that acquired it. Once a thread has acquired a reentrant lock, the same thread may acquire it again without blocking; the thread must release it once for each time it has acquired it. N)Ú_CRLockÚ_PyRLock)ÚargsÚkwargsr"r"r#rQs  c@sVeZdZdZdd„Zdd„Zddd „ZeZd d „Zd d „Z dd„Z dd„Z dd„Z dS)Ú_RLocka,This class implements reentrant lock objects. A reentrant lock must be released by the thread that acquired it. Once a thread has acquired a reentrant lock, the same thread may acquire it again without blocking; the thread must release it once for each time it has acquired it. cCstƒ|_d|_d|_dS©Nr)Ú_allocate_lockÚ_blockÚ_ownerÚ_count©Úselfr"r"r#Ú__init__hsz_RLock.__init__c Cs^|j}zt|j}Wntk r(YnXd|j ¡r:dnd|jj|jj||j t t |ƒƒfS)Nz)<%s %s.%s object owner=%r count=%d at %s>ÚlockedZunlocked) r-Ú_activeÚnameÚKeyErrorr,r2Ú __class__Ú __module__Ú __qualname__r.ÚhexÚid)r0Úownerr"r"r#Ú__repr__ms úz_RLock.__repr__TéÿÿÿÿcCsDtƒ}|j|kr"|jd7_dS|j ||¡}|r@||_d|_|S)aAcquire a lock, blocking or non-blocking. When invoked without arguments: if this thread already owns the lock, increment the recursion level by one, and return immediately. Otherwise, if another thread owns the lock, block until the lock is unlocked. Once the lock is unlocked (not owned by any thread), then grab ownership, set the recursion level to one, and return. If more than one thread is blocked waiting until the lock is unlocked, only one at a time will be able to grab ownership of the lock. There is no return value in this case. When invoked with the blocking argument set to true, do the same thing as when called without arguments, and return true. When invoked with the blocking argument set to false, do not block. If a call without an argument would block, return false immediately; otherwise, do the same thing as when called without arguments, and return true. When invoked with the floating-point timeout argument set to a positive value, block for at most the number of seconds specified by timeout and as long as the lock cannot be acquired. Return true if the lock has been acquired, false if the timeout has elapsed. é)rr-r.r,Úacquire)r0ÚblockingÚtimeoutÚmeÚrcr"r"r#r?|s z_RLock.acquirecCs<|jtƒkrtdƒ‚|jd|_}|s8d|_|j ¡dS)amRelease a lock, decrementing the recursion level. If after the decrement it is zero, reset the lock to unlocked (not owned by any thread), and if any other threads are blocked waiting for the lock to become unlocked, allow exactly one of them to proceed. If after the decrement the recursion level is still nonzero, the lock remains locked and owned by the calling thread. Only call this method when the calling thread owns the lock. A RuntimeError is raised if this method is called when the lock is unlocked. There is no return value. úcannot release un-acquired lockr>N)r-rÚ RuntimeErrorr.r,Úrelease)r0rr"r"r#rF¢s  z_RLock.releasecCs | ¡dS©N©rF©r0ÚtÚvÚtbr"r"r#Ú__exit__¹sz_RLock.__exit__cCs|j ¡|\|_|_dSrG)r,r?r.r-)r0Ústater"r"r#Ú_acquire_restore¾s z_RLock._acquire_restorecCs<|jdkrtdƒ‚|j}d|_|j}d|_|j ¡||fS)NrrD)r.rEr-r,rF)r0rr;r"r"r#Ú _release_saveÂs  z_RLock._release_savecCs |jtƒkSrG)r-rr/r"r"r#Ú _is_ownedÌsz_RLock._is_ownedN)Tr=) Ú__name__r7r8Ú__doc__r1r<r?Ú __enter__rFrMrOrPrQr"r"r"r#r)^s  $ r)c@steZdZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z ddd„Z ddd„Z ddd„Z dd„ZeZdS)r ajClass that implements a condition variable. A condition variable allows one or more threads to wait until they are notified by another thread. If the lock argument is given and not None, it must be a Lock or RLock object, and it is used as the underlying lock. Otherwise, a new RLock object is created and used as the underlying lock. NcCs–|dkrtƒ}||_|j|_|j|_z |j|_Wntk rDYnXz |j|_Wntk rfYnXz |j|_Wntk rˆYnXtƒ|_ dSrG) rÚ_lockr?rFrPÚAttributeErrorrOrQÚ_dequeÚ_waiters©r0Úlockr"r"r#r1Þs$   zCondition.__init__cCs |j ¡SrG)rUrTr/r"r"r#rTöszCondition.__enter__cGs |jj|ŽSrG)rUrM)r0r'r"r"r#rMùszCondition.__exit__cCsd|jt|jƒfS)Nz)rUÚlenrXr/r"r"r#r<üszCondition.__repr__cCs|j ¡dSrG)rUrFr/r"r"r#rPÿszCondition._release_savecCs|j ¡dSrG)rUr?)r0Úxr"r"r#rOszCondition._acquire_restorecCs"|j d¡r|j ¡dSdSdS)NrFT)rUr?rFr/r"r"r#rQs  zCondition._is_ownedcCs°| ¡stdƒ‚tƒ}| ¡|j |¡| ¡}d}z>|dkrN| ¡d}n |dkrd| d|¡}n | d¡}|W¢S| |¡|sªz|j |¡Wnt k r¨YnXXdS)akWait until notified or until a timeout occurs. If the calling thread has not acquired the lock when this method is called, a RuntimeError is raised. This method releases the underlying lock, and then blocks until it is awakened by a notify() or notify_all() call for the same condition variable in another thread, or until the optional timeout occurs. Once awakened or timed out, it re-acquires the lock and returns. When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). When the underlying lock is an RLock, it is not released using its release() method, since this may not actually unlock the lock when it was acquired multiple times recursively. Instead, an internal interface of the RLock class is used, which really unlocks it even when it has been recursively acquired several times. Another internal interface is then used to restore the recursion level when the lock is reacquired. zcannot wait on un-acquired lockFNTr) rQrEr+r?rXÚappendrPrOÚremoveÚ ValueError)r0rAÚwaiterZ saved_stateZgotitr"r"r#Úwaits*   zCondition.waitcCsXd}|}|ƒ}|sT|dk rB|dkr.tƒ|}n|tƒ}|dkrBqT| |¡|ƒ}q|S)zÜWait until a condition evaluates to True. predicate should be a callable which result will be interpreted as a boolean value. A timeout may be provided giving the maximum time to wait. Nr)Ú_timera)r0Z predicaterAÚendtimeZwaittimeÚresultr"r"r#Úwait_for>s   zCondition.wait_forr>c Csf| ¡stdƒ‚|j}tt||ƒƒ}|s,dS|D]0}| ¡z| |¡Wq0tk r^Yq0Xq0dS)aKWake up one or more threads waiting on this condition, if any. If the calling thread has not acquired the lock when this method is called, a RuntimeError is raised. This method wakes up at most n of the threads waiting for the condition variable; it is a no-op if no threads are waiting. z!cannot notify on un-acquired lockN)rQrErXrWÚ_islicerFr^r_)r0ÚnZ all_waitersZwaiters_to_notifyr`r"r"r#ÚnotifyUs zCondition.notifycCs| t|jƒ¡dS)z¯Wake up all threads waiting on this condition. If the calling thread has not acquired the lock when this method is called, a RuntimeError is raised. N)rhr[rXr/r"r"r#Ú notify_alllszCondition.notify_all)N)N)N)r>)rRr7r8rSr1rTrMr<rPrOrQrarerhriZ notifyAllr"r"r"r#r Òs  0   c@s8eZdZdZd dd„Zddd„ZeZd d „Zd d „ZdS)raGThis class implements semaphore objects. Semaphores manage a counter representing the number of release() calls minus the number of acquire() calls, plus an initial value. The acquire() method blocks if necessary until it can return without making the counter negative. If not given, value defaults to 1. r>cCs&|dkrtdƒ‚ttƒƒ|_||_dS)Nrz$semaphore initial value must be >= 0)r_r rÚ_condÚ_value©r0Úvaluer"r"r#r1„s zSemaphore.__init__TNc Cs’|s|dk rtdƒ‚d}d}|j�f|jdkrr|s4q„|dk rd|dkrPtƒ|}n|tƒ}|dkrdq„|j |¡q$|jd8_d}W5QRX|S)aÔAcquire a semaphore, decrementing the internal counter by one. When invoked without arguments: if the internal counter is larger than zero on entry, decrement it by one and return immediately. If it is zero on entry, block, waiting until some other thread has called release() to make it larger than zero. This is done with proper interlocking so that if multiple acquire() calls are blocked, release() will wake exactly one of them up. The implementation may pick one at random, so the order in which blocked threads are awakened should not be relied on. There is no return value in this case. When invoked with blocking set to true, do the same thing as when called without arguments, and return true. When invoked with blocking set to false, do not block. If a call without an argument would block, return false immediately; otherwise, do the same thing as when called without arguments, and return true. When invoked with a timeout other than None, it will block for at most timeout seconds. If acquire does not complete successfully in that interval, return false. Return true otherwise. Nz.can't specify timeout for non-blocking acquireFrr>T)r_rjrkrbra)r0r@rArCrcr"r"r#r?Šs$    zSemaphore.acquirec Cs.|j�|jd7_|j ¡W5QRXdS)z×Release a semaphore, incrementing the internal counter by one. When the counter is zero on entry and another thread is waiting for it to become larger than zero again, wake up that thread. r>N)rjrkrhr/r"r"r#rF¹szSemaphore.releasecCs | ¡dSrGrHrIr"r"r#rMÄszSemaphore.__exit__)r>)TN) rRr7r8rSr1r?rTrFrMr"r"r"r#rxs   - c@s"eZdZdZddd„Zdd„ZdS) ra©Implements a bounded semaphore. A bounded semaphore checks to make sure its current value doesn't exceed its initial value. If it does, ValueError is raised. In most situations semaphores are used to guard resources with limited capacity. If the semaphore is released too many times it's a sign of a bug. If not given, value defaults to 1. Like regular semaphores, bounded semaphores manage a counter representing the number of release() calls minus the number of acquire() calls, plus an initial value. The acquire() method blocks if necessary until it can return without making the counter negative. If not given, value defaults to 1. r>cCst ||¡||_dSrG)rr1Ú_initial_valuerlr"r"r#r1Ùs zBoundedSemaphore.__init__c CsB|j�2|j|jkrtdƒ‚|jd7_|j ¡W5QRXdS)a6Release a semaphore, incrementing the internal counter by one. When the counter is zero on entry and another thread is waiting for it to become larger than zero again, wake up that thread. If the number of releases exceeds the number of acquires, raise a ValueError. z!Semaphore released too many timesr>N)rjrkrnr_rhr/r"r"r#rFÝs  zBoundedSemaphore.releaseN)r>)rRr7r8rSr1rFr"r"r"r#rÈs c@sFeZdZdZdd„Zdd„Zdd„ZeZdd „Zd d „Z dd d„Z d S)rzòClass implementing event objects. Events manage a flag that can be set to true with the set() method and reset to false with the clear() method. The wait() method blocks until the flag is true. The flag is initially false. cCsttƒƒ|_d|_dS)NF)r rrjÚ_flagr/r"r"r#r1ùs zEvent.__init__cCs|j tƒ¡dSrG)rjr1rr/r"r"r#Ú_reset_internal_locksýszEvent._reset_internal_lockscCs|jS)z5Return true if and only if the internal flag is true.)ror/r"r"r#Úis_setsz Event.is_setc Cs&|j�d|_|j ¡W5QRXdS)z·Set the internal flag to true. All threads waiting for it to become true are awakened. Threads that call wait() once the flag is true will not block at all. TN)rjrorir/r"r"r#Úsetsz Event.setc Cs|j� d|_W5QRXdS)zªReset the internal flag to false. Subsequently, threads calling wait() will block until set() is called to set the internal flag to true again. FN)rjror/r"r"r#Úclearsz Event.clearNc Cs8|j�(|j}|s|j |¡}|W5QR£SQRXdS)aHBlock until the internal flag is true. If the internal flag is true on entry, return immediately. Otherwise, block until another thread calls set() to set the flag to true, or until the optional timeout occurs. When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). This method returns the internal flag on exit, so it will always return True except if a timeout is given and the operation times out. N)rjrora)r0rAZsignaledr"r"r#ras  z Event.wait)N) rRr7r8rSr1rprqZisSetrrrsrar"r"r"r#rîs   c@s€eZdZdZddd„Zddd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z e dd„ƒZe dd„ƒZe dd„ƒZdS)rzØImplements a Barrier. Useful for synchronizing a fixed number of threads at known synchronization points. Threads block on 'wait()' and are simultaneously awoken once they have all made that call. NcCs.ttƒƒ|_||_||_||_d|_d|_dS)aWCreate a barrier, initialised to 'parties' threads. 'action' is a callable which, when supplied, will be called by one of the threads after they have all entered the barrier and just prior to releasing them all. If a 'timeout' is provided, it is used as the default for all subsequent 'wait()' calls. rN)r rrjÚ_actionÚ_timeoutÚ_partiesÚ_stater.)r0ÚpartiesÚactionrAr"r"r#r1Fs zBarrier.__init__c Cs�|dkr|j}|j�r| ¡|j}|jd7_z6|d|jkrL| ¡n | |¡|W¢W5QR£S|jd8_| ¡XW5QRXdS)aNWait for the barrier. When the specified number of threads have started waiting, they are all simultaneously awoken. If an 'action' was provided for the barrier, one of the threads will have executed that callback prior to returning. Returns an individual index number from 0 to 'parties-1'. Nr>)rurjÚ_enterr.Ú_exitrvÚ_releaseÚ_wait)r0rAÚindexr"r"r#raVs   z Barrier.waitcCs6|jdkr|j ¡q|jdkr$t‚|jdks2t‚dS)N©r=r>r)rwrjrarÚAssertionErrorr/r"r"r#rzts    zBarrier._entercCs>z"|jr| ¡d|_|j ¡Wn| ¡‚YnXdS)Nr>)rtrwrjriÚ_breakr/r"r"r#r|szBarrier._releasecsBˆj ‡fdd„|¡s"ˆ ¡t‚ˆjdkr0t‚ˆjdks>t‚dS)Ncs ˆjdkSr*©rwr"r/r"r#ÚŽózBarrier._wait..rr>)rjrer�rrwr€©r0rAr"r/r#r}�s  z Barrier._waitcCs(|jdkr$|jdkr$d|_|j ¡dS)Nrr)r.rwrjrir/r"r"r#r{˜s  z Barrier._exitc CsT|j�D|jdkr6|jdkr$d|_q<|jdkrReturn the number of threads currently waiting at the barrier.r)rwr.r/r"r"r#Ú n_waitingÈs zBarrier.n_waitingcCs |jdkS)z0Return True if the barrier is in a broken state.r†r‚r/r"r"r#ÚbrokenÑszBarrier.broken)NN)N)rRr7r8rSr1rarzr|r}r{r‡rˆr�Úpropertyrxr‰rŠr"r"r"r#r=s        c@s eZdZdS)rN)rRr7r8r"r"r"r#r×sú Thread-%dcCs |tƒSrG)Ú_counter)Útemplater"r"r#Ú_newnameÞsr�c@seZdZdZdZd:ddœdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z e r\dd„Z dd„Zdd„Zdd„Zdd„Zd;dd„Zd) ržr€rœrqrªr�r—r˜r6rRr”)r0Zstatusr"r"r#r<4s  zThread.__repr__c Cs„|jstdƒ‚|j ¡r tdƒ‚t�|t|<W5QRXzt|jdƒWn,tk rtt� t|=W5QRX‚YnX|j  ¡dS)a-Start the thread's activity. It must be called at most once per thread object. It arranges for the object's run() method to be invoked in a separate thread of control. This method will raise a RuntimeError if called more than once on the same thread object. zthread.__init__() not calledz threads can only be started oncer"N) ržrErœrqÚ_active_limbo_lockÚ_limboÚ_start_new_threadÚ _bootstrapÚ Exceptionrar/r"r"r#ÚstartBs  z Thread.startcCs.z|jr|j|j|jŽW5|`|`|`XdS)aXMethod representing the thread's activity. You may override this method in a subclass. The standard run() method invokes the callable object passed to the object's constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively. N)r’r•r–r/r"r"r#Úrun[s z Thread.runcCs4z | ¡Wn"|jr(tdkr(YdS‚YnXdSrG)Ú_bootstrap_innerr—rŸr/r"r"r#r¯ls  zThread._bootstrapcCs tƒ|_dSrG)rr˜r/r"r"r#Ú _set_ident€szThread._set_identcCs tƒ|_dSrG)rršr/r"r"r#Ú_set_native_id„szThread._set_native_idc Cs8tƒ|_|j ¡|js4t�t |j¡W5QRXdS)z” Set a lock object which will be released by the interpreter when the underlying thread state (see pystate.h) gets deleted. N)Ú _set_sentinelr›r?r‘Ú_shutdown_locks_lockÚ_shutdown_locksr¥r/r"r"r#r©‡s  zThread._set_tstate_lockcCs¼zŠ| ¡| ¡tr| ¡|j ¡t�|t|j <t |=W5QRXt rVt   t ¡trdt  t¡z | ¡Wn| |¡YnXW5t� z ttƒ=Wn YnXW5QRXXdSrG)r¬r3rr´r©r™rµrœrrr˜r­r$rŸrrrr²r£r/r"r"r#r³“s,      zThread._bootstrap_innerc CsJ|j}|dk r| ¡rt‚d|_d|_|jsFt�t |¡W5QRXdSr¨)r›r2r€r�r‘r·r¸ÚdiscardrYr"r"r#Ú_stop°s z Thread._stopc Cst�ttƒ=W5QRXdS)zARemove current thread from the dict of currently running threads.N)r¬r3rr/r"r"r#Ú_deleteÊszThread._deletecCsZ|jstdƒ‚|j ¡s tdƒ‚|tƒkr2tdƒ‚|dkrD| ¡n|jt|dƒd�dS)aWait until the thread terminates. This blocks the calling thread until the thread whose join() method is called terminates -- either normally or through an unhandled exception or until the optional timeout occurs. When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened -- if the thread is still alive, the join() call timed out. When the timeout argument is not present or None, the operation will block until the thread terminates. A thread can be join()ed many times. join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception. úThread.__init__() not calledz'cannot join thread before it is startedzcannot join current threadNr)rA)ržrErœrqr Ú_wait_for_tstate_lockÚmaxr…r"r"r#ÚjoinÓs   z Thread.joinTr=cCs:|j}|dkr|js6t‚n| ||¡r6| ¡| ¡dSrG)r›r�r€r?rFrº)r0ÚblockrArZr"r"r#r½ùs   zThread._wait_for_tstate_lockcCs|jstdƒ‚|jS)z¸A string used for identification purposes only. It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor. r¼)ržr€r”r/r"r"r#r4sz Thread.namecCs|jstdƒ‚t|ƒ|_dS)Nr¼)ržr€r“r”©r0r4r"r"r#r4scCs|jstdƒ‚|jS)a4Thread identifier of this thread or None if it has not been started. This is a nonzero integer. See the get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited. r¼)ržr€r˜r/r"r"r#Úidents z Thread.identcCs|jstdƒ‚|jS)zïNative integral thread ID of this thread, or None if it has not been started. This is a non-negative integer. See the get_native_id() function. This represents the Thread ID as reported by the kernel. r¼)ržr€ršr/r"r"r#Ú native_id$szThread.native_idcCs4|jstdƒ‚|js|j ¡s"dS| d¡|j S)zöReturn whether the thread is alive. This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads. r¼F)ržr€r�rœrqr½r/r"r"r#rª/s  zThread.is_alivecCs ddl}|jdtdd�| ¡S)zhReturn whether the thread is alive. This method is deprecated, use is_alive() instead. rNz/isAlive() is deprecated, use is_alive() insteadé)Ú stacklevel)ÚwarningsÚwarnÚDeprecationWarningrª)r0rÆr"r"r#ÚisAlive=s ÿzThread.isAlivecCs|jstdƒ‚|jS)a¶A boolean value indicating whether this thread is a daemon thread. This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False. The entire Python program exits when only daemon threads are left. r¼)ržr€r—r/r"r"r#r‘Gs z Thread.daemoncCs*|jstdƒ‚|j ¡r tdƒ‚||_dS)Nr¼z)cannot set daemon status of active thread)ržrErœrqr—©r0Zdaemonicr"r"r#r‘Vs  cCs|jSrGr�r/r"r"r#ÚisDaemon^szThread.isDaemoncCs ||_dSrGr�rÊr"r"r#Ú setDaemonaszThread.setDaemoncCs|jSrG©r4r/r"r"r#ÚgetNamedszThread.getNamecCs ||_dSrGrÍrÁr"r"r#ÚsetNamegszThread.setName)NNNr"N)N)Tr=) rRr7r8rSržr1rpr<r±r²r¯r´r™rµr©r³rºr»r¿r½r‹r4ÚsetterrÂrÃrªrÉr‘rËrÌrÎrÏr"r"r"r#rîsRÿÿ /   &        )Ú _excepthookÚ_ExceptHookArgs)Úprint_exception)Ú namedtuplez'exc_type exc_value exc_traceback threadcCst|ŽSrG)rÒ)r'r"r"r#rwscCsž|jtkrdStdk r(tjdk r(tj}n$|jdk rH|jj}|dkrLdSndS|jdk r`|jj}ntƒ}td|›d�|dd�t |j|j |j |d�|  ¡dS)z9 Handle uncaught Thread.run() exception. NzException in thread ú:T©ÚfileÚflush)r×) Úexc_typeÚ SystemExitrŸr Úthreadr¡r4rÚprintÚ_print_exceptionÚ exc_valueÚ exc_tracebackrØ)r'r r4r"r"r#rzs(     ÿÿcsPt‰tj‰ˆdkrtdƒ‚ˆdkr*tdƒ‚tj‰t‰t‰‡‡‡‡‡fdd„}|S)Nzthreading.excepthook is Nonezsys.excepthook is Nonec s¾z²z,t}|dkrˆ}tˆƒ|f•ƒ}||ƒWn€tk r®}zbd|_~ˆdk rbˆjdk rbˆj}n|j}ˆd|dd�ˆdk r�ˆjdk r�ˆj}nˆ}|ˆƒŽW5d}~XYnXW5d}XdS)NTz"Exception in threading.excepthook:rÖ)rrr°Ú__suppress_context__r r¡)rÛr'ÚhookÚexcr Zsys_excepthook©Z local_printZ local_sysZold_excepthookZold_sys_excepthookZ sys_exc_infor"r#Úinvoke_excepthook©s* ÿ z2_make_invoke_excepthook..invoke_excepthook)rrŸrEÚexc_inforÜ)rär"rãr#r¢™s r¢c@s*eZdZdZd dd„Zdd„Zdd„ZdS) rzÓCall a function after a specified number of seconds: t = Timer(30.0, f, args=None, kwargs=None) t.start() t.cancel() # stop the timer's action if it's still waiting NcCsFt |¡||_||_|dk r"|ng|_|dk r4|ni|_tƒ|_dSrG)rr1ÚintervalÚfunctionr'r(rÚfinished)r0rærçr'r(r"r"r#r1×s  zTimer.__init__cCs|j ¡dS)z)Stop the timer if it hasn't finished yet.N)rèrrr/r"r"r#Úcancelßsz Timer.cancelcCs6|j |j¡|j ¡s(|j|j|jŽ|j ¡dSrG)rèrarærqrçr'r(rrr/r"r"r#r²ãs z Timer.run)NN)rRr7r8rSr1rér²r"r"r"r#rÎs c@seZdZdd„ZdS)Ú _MainThreadc CsTtj|ddd�| ¡|j ¡| ¡tr6| ¡t�|t |j <W5QRXdS)NZ MainThreadF©r4r‘) rr1r©rœrrr´r™rµr¬r3r˜r/r"r"r#r1îs z_MainThread.__init__N)rRr7r8r1r"r"r"r#rêìsrêc@s.eZdZdd„Zdd„Zdd„Zd dd „ZdS) Ú _DummyThreadc CsPtj|tdƒdd�|j ¡| ¡tr2| ¡t�|t |j <W5QRXdS)NzDummy-%dTrë) rr1r�rœrrr´r™rµr¬r3r˜r/r"r"r#r1s z_DummyThread.__init__cCsdSrGr"r/r"r"r#rº sz_DummyThread._stopcCs|js|j ¡st‚dSr¨)r�rœrqr€r/r"r"r#rªsz_DummyThread.is_aliveNcCsds tdƒ‚dS)NFzcannot join a dummy thread)r€r…r"r"r#r¿sz_DummyThread.join)N)rRr7r8r1rºrªr¿r"r"r"r#rìs rìcCs,z ttƒWStk r&tƒYSXdS)zïReturn the current Thread object, corresponding to the caller's thread of control. If the caller's thread of control was not created through the threading module, a dummy thread object with limited functionality is returned. N)r3rr5rìr"r"r"r#r s c Cs,t�ttƒttƒW5QR£SQRXdS)z’Return the number of Thread objects currently alive. The returned count is equal to the length of the list returned by enumerate(). N)r¬r[r3r­r"r"r"r#r(scCstt ¡ƒtt ¡ƒSrG)Úlistr3Úvaluesr­r"r"r"r#Ú _enumerate4srïc Cs4t�&tt ¡ƒtt ¡ƒW5QR£SQRXdS)zýReturn a list of all Thread objects currently alive. The list includes daemonic threads, dummy thread objects created by current_thread(), and the main thread. It excludes terminated threads and threads that have not yet been started. N)r¬rír3rîr­r"r"r"r#r 8s)rc Cs~tjr dStj}|dk st‚| ¡s(t‚| ¡t ¡t�tt ƒ}t   ¡W5QRX|s^qz|D]}|  ¡| ¡qbq8dS)zS Wait until the Python thread state of all non-daemon threads get deleted. N) Ú _main_threadr�r›r€r2rFrºr·rír¸rsr?)ZtlockZlocksrZr"r"r#Ú _shutdownKs   rñcCstS)z�Return the main thread object. In normal conditions, the main thread is the thread from which the Python interpreter was started. )rðr"r"r"r#r ss)Ú_local)rc CsÚtƒai}zttƒ}Wntk r2tƒ}YnX|atƒatƒa t�ˆtt ƒƒ}|  t ¡|D]>}||krŽ|  d¡tƒ}||_|||<qb|  d¡| ¡qbt ¡t ¡t  |¡ttƒdksÌt‚W5QRXdS)zL Cleanup threading module state that should not exist after a fork. TFr>N)r+r¬r3rr5rêrðr·rrr¸rïÚupdater¤rpr˜rºr­rsr[r€)Z new_activeZcurrentZthreadsrÛrÂr"r"r#Ú _after_fork„s0        rôÚregister_at_fork)Zafter_in_child)rŒ)ZrSÚosÚ_osÚsysrŸÚ_threadÚtimerrbZ _weakrefsetrÚ itertoolsrrfrr.Ú _collectionsrrWÚ ImportErrorÚ collectionsÚ__all__Ústart_new_threadr®Ú allocate_lockr+r¶rrr™r]rVÚerrorrrr%r rr$rrrr)r&r rrrrrErÚ__next__r�r�r¬r3r­r¤r·rrr¸rrÑrrÒrÚ tracebackrÓrÝrÔr¢rrêrìr Z currentThreadrZ activeCountrïr rrðrñr ròrZ_threading_localrôÚhasattrrõr"r"r"r#ÚsÚ   û      q'P&O   þ5   ( 5