U e5d@s2dZddlZddlZddlZddlmZddl m Z ddl m Z mZzddlmZWn ek rtddlmZYnXddd d d d d ddddddddddddddddgZejZejZejZejZzejZdZedWnek rd ZYnXej Z!z ej"Z#Wnek rdZ#YnXej$Z$[da%da&d!dZ'd"dZ(eZ)d#dZ"Gd$d%d%Z*e*Z+Gd&d d Z,Gd'ddZ-Gd(dde-Z.Gd)ddZ/Gd*ddZ0Gd+dde1Z2ej3Z4e4dLd-d.Z5ea6iZ7iZ8e Z9ea:e;aa?m@ZAWnHek rVdd1lBmCZDdd2lmEZEeEdd3Z@d4dZAd5da?YnXd6d7ZFGd8dde=ZGGd9d:d:e=ZHGd;d<ddZLeLZMd?d@ZNdAd ZOddBlmPZPeHaQdCdDZRdEd ZSzddFlmTZUWn"ek r ddGlVmUZUYnXdHdIZWeXedJr.ejYeWdKdS)Mz;Thread module emulating a subset of Java's threading model.N) monotonic)WeakSet)islicecount)deque get_ident active_count Conditioncurrent_thread enumerate main_thread TIMEOUT_MAXEventLockRLock SemaphoreBoundedSemaphoreThreadBarrierBrokenBarrierErrorTimer ThreadError setprofilesettracelocal stack_size excepthookExceptHookArgsT get_native_idFcCs|adS)zSet 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_hookfuncr"!/usr/lib64/python3.8/threading.pyr9scCs|adS)zSet 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)argskwargsr"r"r#rQs  c@sVeZdZdZddZddZddd ZeZd d Zd d Z ddZ ddZ ddZ 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|_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,r2 __class__ __module__ __qualname__r.hexid)r0ownerr"r"r#__repr__ms z_RLock.__repr__TcCsDt}|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)r0blockingtimeoutmercr"r"r#r?|s z_RLock.acquirecCs<|jtkrtd|jd|_}|s8d|_|jdS)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#rFs  z_RLock.releasecCs |dSNrFr0tvtbr"r"r#__exit__sz_RLock.__exit__cCs|j|\|_|_dSrG)r,r?r.r-)r0stater"r"r#_acquire_restores z_RLock._acquire_restorecCs<|jdkrtd|j}d|_|j}d|_|j||fS)NrrD)r.rEr-r,rF)r0rr;r"r"r# _release_saves  z_RLock._release_savecCs |jtkSrG)r-rr/r"r"r# _is_ownedsz_RLock._is_ownedN)Tr=) __name__r7r8__doc__r1r<r? __enter__rFrMrOrPrQr"r"r"r#r)^s  $ r)c@steZdZdZdddZddZddZd d Zd d Zd dZ ddZ dddZ dddZ dddZ ddZeZdS)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 rYnXt|_ dSrG) r_lockr?rFrPAttributeErrorrOrQ_deque_waitersr0lockr"r"r#r1s$   zCondition.__init__cCs |jSrG)rUrTr/r"r"r#rTszCondition.__enter__cGs |jj|SrG)rUrM)r0r'r"r"r#rMszCondition.__exit__cCsd|jt|jfS)Nz)rUlenrXr/r"r"r#r<szCondition.__repr__cCs|jdSrG)rUrFr/r"r"r#rPszCondition._release_savecCs|jdSrG)rUr?)r0xr"r"r#rOszCondition._acquire_restorecCs"|jdr|jdSdSdS)NrFT)rUr?rFr/r"r"r#rQs  zCondition._is_ownedcCs|stdt}||j||}d}z>|dkrN|d}n |dkrd|d|}n |d}|WS|||sz|j|Wnt k rYnXXdS)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?rXappendrPrOremove ValueError)r0rAwaiterZ saved_stateZgotitr"r"r#waits*   zCondition.waitcCsXd}|}|}|sT|dk rB|dkr.t|}n|t}|dkrBqT|||}q|S)zWait 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 predicaterAendtimeZwaittimeresultr"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_)r0nZ all_waitersZwaiters_to_notifyr`r"r"r#notifyUs zCondition.notifycCs|t|jdS)zWake 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 ddZdddZeZd 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&|dkrtdtt|_||_dS)Nrz$semaphore initial value must be >= 0)r_r r_cond_valuer0valuer"r"r#r1s zSemaphore.__init__TNc Cs|s|dk rtdd}d}|jf|jdkrr|s4q|dk rd|dkrPt|}n|t}|dkrdq|j|q$|jd8_d}W5QRX|S)aAcquire 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_|jW5QRXdS)zRelease 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#rFszSemaphore.releasecCs |dSrGrHrIr"r"r#rMszSemaphore.__exit__)r>)TN) rRr7r8rSr1r?rTrFrMr"r"r"r#rxs   - c@s"eZdZdZdddZddZdS) raImplements 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#r1s zBoundedSemaphore.__init__c CsB|j2|j|jkrtd|jd7_|jW5QRXdS)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#rFs  zBoundedSemaphore.releaseN)r>)rRr7r8rSr1rFr"r"r"r#rs c@sFeZdZdZddZddZddZeZdd Zd d Z dd dZ d S)rzClass 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#r1s zEvent.__init__cCs|jtdSrG)rjr1rr/r"r"r#_reset_internal_locksszEvent._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&|jd|_|jW5QRXdS)zSet 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)zReset 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|}|W5QRSQRXdS)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#rs   c@seZdZdZdddZdddZddZd d Zd d Zd dZ ddZ ddZ ddZ e ddZe ddZe ddZdS)rzImplements 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.)r0partiesactionrAr"r"r#r1Fs zBarrier.__init__c Cs|dkr|j}|jr||j}|jd7_z6|d|jkrL|n |||WW5QRS|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)r0rAindexr"r"r#raVs   z Barrier.waitcCs(|jdkr|jq|jdkr$tdS)Nr=r>r)rwrjrarr/r"r"r#rzts    zBarrier._entercCs>z"|jr|d|_|jWn|YnXdS)Nr>)rtrwrjri_breakr/r"r"r#r|szBarrier._releasecs4jfdd|s"tjdkr0tdS)Ncs jdkSr*rwr"r/r"r#zBarrier._wait..r)rjrerrrwr0rAr"r/r#r}s  z Barrier._waitcCs(|jdkr$|jdkr$d|_|jdS)Nrr)r.rwrjrir/r"r"r#r{s  z Barrier._exitc CsT|jD|jdkr6|jdkr$d|_q<|jdkrReturn the number of threads currently waiting at the barrier.r)rwr.r/r"r"r# n_waitings zBarrier.n_waitingcCs |jdkS)z0Return True if the barrier is in a broken state.rrr/r"r"r#brokenszBarrier.broken)NN)N)rRr7r8rSr1rarzr|r}r{rrrpropertyrxrrr"r"r"r#r=s        c@s eZdZdS)rN)rRr7r8r"r"r"r#rs Thread-%dcCs |tSrG)_counter)templater"r"r#_newnamesrc@seZdZdZdZd:ddddZdd Zd d Zd d ZddZ ddZ ddZ e r\ddZ ddZddZddZddZd;ddZd||_n tj|_d|_ t rXd|_ d|_ t |_d|_d|_tj|_t|_t|dS)aKThis constructor should always be called with keyword arguments. Arguments are: *group* should be None; reserved for future extension when a ThreadGroup class is implemented. *target* is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called. *name* is the thread name. By default, a unique name is constructed of the form "Thread-N" where N is a small decimal number. *args* is the argument tuple for the target invocation. Defaults to (). *kwargs* is a dictionary of keyword arguments for the target invocation. Defaults to {}. If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread. 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)r0grouptargetr4r'r(rr"r"r#r1s& zThread.__init__cCs(|j|r|n d|_d|_dSNT)rrp_set_tstate_lockrr)r0is_aliver"r"r#rp(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)>) rrqrrrrr6rRr)r0Zstatusr"r"r#r<4s  zThread.__repr__c Cs|jstd|jr tdt|t|<W5QRXzt|jdWn,tk rtt t|=W5QRXYnX|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) rrErrq_active_limbo_lock_limbo_start_new_thread _bootstrap Exceptionrar/r"r"r#startBs  z Thread.startcCs.z|jr|j|j|jW5|`|`|`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)rrrr/r"r"r#run[s z Thread.runcCs4z |Wn"|jr(tdkr(YdSYnXdSrG)_bootstrap_innerrrr/r"r"r#rls  zThread._bootstrapcCs t|_dSrG)rrr/r"r"r# _set_identszThread._set_identcCs t|_dSrG)rrr/r"r"r#_set_native_idszThread._set_native_idc Cs8t|_|j|js4tt|jW5QRXdS)z Set a lock object which will be released by the interpreter when the underlying thread state (see pystate.h) gets deleted. N) _set_sentinelrr?r_shutdown_locks_lock_shutdown_locksrr/r"r"r#rs  zThread._set_tstate_lockcCsz||tr||jt|t|j <t |=W5QRXt rVt t trdt tz |Wn||YnXW5t z tt=Wn YnXW5QRXXdSrG)rr3rrrrrrrrrrr$rrrrrrr/r"r"r#rs,      zThread._bootstrap_innerc Cs>|j}|dk rd|_d|_|js:tt|W5QRXdSr)rrrrrdiscardrYr"r"r#_stopsz Thread._stopc Csttt=W5QRXdS)zARemove current thread from the dict of currently running threads.N)rr3rr/r"r"r#_deleteszThread._deletecCsZ|jstd|js td|tkr2td|dkrD|n|jt|dddS)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)rrErrqr _wait_for_tstate_lockmaxrr"r"r#joins   z Thread.joinTr=cCs0|j}|dkrn|||r,||dSrG)rr?rFr)r0blockrArZr"r"r#rs  zThread._wait_for_tstate_lockcCs|jS)zA 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. )rr/r"r"r#r4s z Thread.namecCst||_dSrG)rrr0r4r"r"r#r4scCs|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. )rr/r"r"r#idents z Thread.identcCs|jS)zNative 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. )rr/r"r"r# native_id$s zThread.native_idcCs&|js|jsdS|d|j S)zReturn 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. F)rrrqrr/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)warningswarnDeprecationWarningr)r0rr"r"r#isAlive=s zThread.isAlivecCs|jS)aA 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. )rr/r"r"r#rGs z Thread.daemoncCs*|jstd|jr td||_dS)Nrz)cannot set daemon status of active thread)rrErrqrr0Zdaemonicr"r"r#rVs  cCs|jSrGrr/r"r"r#isDaemon^szThread.isDaemoncCs ||_dSrGrrr"r"r# setDaemonaszThread.setDaemoncCs|jSrGr4r/r"r"r#getNamedszThread.getNamecCs ||_dSrGrrr"r"r#setNamegszThread.setName)NNNr"N)N)Tr=) rRr7r8rSrr1rpr<rrrrrrrrrrrrrr4setterrrrrrrrrrr"r"r"r#rsR /   &        ) _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|ddt |j|j |j |d| dS)z9 Handle uncaught Thread.run() exception. NzException in thread :Tfileflush)r) exc_type SystemExitrrthreadrr4rprint_print_exception exc_value exc_tracebackr)r'rr4r"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)rrrEexc_infor)rr"rr#rs rc@s*eZdZdZd ddZddZddZdS) rzCall 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)rr1intervalfunctionr'r(rfinished)r0rrr'r(r"r"r#r1s  zTimer.__init__cCs|jdS)z)Stop the timer if it hasn't finished yet.N)rrrr/r"r"r#cancelsz Timer.cancelcCs6|j|j|js(|j|j|j|jdSrG)rrarrqrr'r(rrr/r"r"r#rs z Timer.run)NN)rRr7r8rSr1rrr"r"r"r#rs c@seZdZddZdS) _MainThreadc CsTtj|ddd||j|tr6|t|t |j <W5QRXdS)NZ MainThreadFr4r) rr1rrrrrrrrr3rr/r"r"r#r1s z_MainThread.__init__N)rRr7r8r1r"r"r"r#rsrc@s.eZdZddZddZddZd dd ZdS) _DummyThreadc CsPtj|tddd|j|tr2|t|t |j <W5QRXdS)NzDummy-%dTr) rr1rrrrrrrrr3rr/r"r"r#r1s z_DummyThread.__init__cCsdSrGr"r/r"r"r#r sz_DummyThread._stopcCsdSrr"r/r"r"r#rsz_DummyThread.is_aliveNcCsdSrGr"rr"r"r#rsz_DummyThread.join)N)rRr7r8r1rrrr"r"r"r#rs rcCs,z ttWStk r&tYSXdS)zReturn 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)r3rr5rr"r"r"r#r s c Cs,tttttW5QRSQRXdS)zReturn the number of Thread objects currently alive. The returned count is equal to the length of the list returned by enumerate(). N)rr[r3rr"r"r"r#r(scCsttttSrG)listr3valuesrr"r"r"r# _enumerate4src Cs4t&ttttW5QRSQRXdS)zReturn 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)rrr3rrr"r"r"r#r 8s)rc Csftjr dStj}|tttt}tW5QRX|sFqb|D]}| |qJq dS)zS Wait until the Python thread state of all non-daemon threads get deleted. N) _main_threadrrrFrrrrrsr?)ZtlockZlocksrZr"r"r# _shutdownKs rcCstS)zReturn the main thread object. In normal conditions, the main thread is the thread from which the Python interpreter was started. )rr"r"r"r#r ss)_local)rc Cstai}ztt}Wntk r2t}YnX|atata txtt }| t |D]>}||kr| dt}||_|||<qb| d|qbttt |W5QRXdS)zL Cleanup threading module state that should not exist after a fork. TFN)r+rr3rr5rrrrrrrupdaterrprrrrs)Z new_activeZcurrentZthreadsrrr"r"r# _after_forks0        rregister_at_fork)Zafter_in_child)r)ZrSos_ossysr_threadtimerrbZ _weakrefsetr itertoolsrrfrr. _collectionsrrW ImportError collections__all__start_new_threadr allocate_lockr+rrrrr]rVerrorrrr%r rr$rrrr)r&r rrrrrEr__next__rrrr3rrrrrrrrrrr tracebackrrrrrrrr Z currentThreadrZ activeCountrr rrrr rrZ_threading_localrhasattrrr"r"r"r#s         q'P&O   5   ( 5