o g@s6dZddlZddlZddlZddlZddlmZ ddl m Z ddl m ZmZzddlmZWney=ddlmZYnwgdZejZejZejZejZz ejZdZed Wn e yed ZYnwej!Z"zej#Z$Wn e yydZ$Ynwej%Z%[da&da'd d Z(d dZ)ddZ*ddZ+eZ,ddZ#GdddZ-e-Z.GdddZ/GdddZ0Gddde0Z1GdddZ2Gdd d Z3Gd!d"d"e4Z5ed#j6Z7d$d%Z8e#a9iZ:iZ;e Za?d&d'Z@Gd(d)d)ZAz dd*lmBaCmDZEWn#eydd+lFmGZHdd,lmIZIeId-d.ZDd/d-ZEd0d1aCYnwtCZJd2d3ZKGd4d5d5eAZLGd6d7d7eAZMGd8d9d9eAZNd:d;ZOdd?ZQd@dAZRdBdCZSdDdEZTgZUd aVdFdGZWddHlmXZXeMaYdIdJZZdKdLZ[zddMlm\Z]WneyddNl^m]Z]YnwdOdPZ_e`edQrejae_dRdSdS)Sz;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 excepthookExceptHookArgsgettrace getprofileT get_native_idFcC|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&0/opt/alt/python310/lib64/python3.10/threading.pyr:rcCtS)z;Get the profiler function as set by threading.setprofile().r"r&r&r&r'rDrcCr!)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'rHr(rcCr))z6Get the trace function as set by threading.settrace().r+r&r&r&r'rRr*rcOs$tdur t|i|St|i|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'rZs rc@s^eZdZdZddZddZddZdd d ZeZd d Z ddZ 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__qs z_RLock.__init__c Cs\|j}zt|j}Wn tyYnwd|jrdnd|jj|jj||j t t |fS)Nz)<%s %s.%s object owner=%r count=%d at %s>lockedZunlocked) r5_activenameKeyErrorr4r: __class__ __module__ __qualname__r6hexid)r8ownerr&r&r'__repr__vs  z_RLock.__repr__cCs|jd|_d|_dSr2)r4_at_fork_reinitr5r6r7r&r&r'rEs  z_RLock._at_fork_reinitTcCsDt}|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. )rr5r6r4acquire)r8blockingtimeoutmercr&r&r'rHs z_RLock.acquirecCs@|jtkr td|jd|_}|sd|_|jdSdS)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 lockrGN)r5r RuntimeErrorr6r4release)r8rr&r&r'rOs z_RLock.releasecC |dSNrOr8tvtbr&r&r'__exit__ z_RLock.__exit__cCs|j|\|_|_dSrQ)r4rHr6r5)r8stater&r&r'_acquire_restores z_RLock._acquire_restorecCs<|jdkr td|j}d|_|j}d|_|j||fS)NrrM)r6rNr5r4rO)r8rrCr&r&r' _release_saves  z_RLock._release_savecCs |jtkSrQ)r5rr7r&r&r' _is_ownedrXz_RLock._is_ownedNTrF)__name__r?r@__doc__r9rDrErH __enter__rOrWrZr[r\r&r&r&r'r1gs  $ r1c@seZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ dddZ dddZ dddZddZddZdS) 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|durt}||_|j|_|j|_z|j|_Wn ty!Ynwz|j|_Wn ty1Ynwz|j|_Wn tyAYnwt|_ dSrQ) r_lockrHrOr[AttributeErrorrZr\_deque_waitersr8lockr&r&r'r9s*       zCondition.__init__cCs|j|jdSrQ)rarErdclearr7r&r&r'rEs zCondition._at_fork_reinitcCs |jSrQ)rar`r7r&r&r'r` zCondition.__enter__cGs |jj|SrQ)rarW)r8r/r&r&r'rW rXzCondition.__exit__cCsd|jt|jfS)Nz)ralenrdr7r&r&r'rDszCondition.__repr__cC|jdSrQ)rarOr7r&r&r'r[zCondition._release_savecCrjrQ)rarH)r8xr&r&r'rZrkzCondition._acquire_restorecCs|jdr |jdSdS)NFT)rarHrOr7r&r&r'r\s  zCondition._is_ownedcCs|stdt}||j||}d}z7|dur'|d}n|dkr2|d|}n|d}|W|||sRz|j|WSt yQYSwS|||slz|j|Wwt ykYwww)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) r\rNr3rHrdappendr[rZremove ValueError)r8rJwaiterZ saved_stateZgotitr&r&r'wait s>      zCondition.waitcCs^d}|}|}|s-|dur#|durt|}n |t}|dkr# |S|||}|r |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)_timerq)r8Z predicaterJendtimeZwaittimeresultr&r&r'wait_forPs    zCondition.wait_forrGcCs|std|j}|rB|dkrD|d}z|Wn ty$Ynw|d8}z||Wn ty9Ynw|rF|dksdSdSdSdS)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 lockrrGN)r\rNrdrOrnro)r8nwaitersrpr&r&r'notifygs"     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)rxrirdr7r&r&r' notify_allszCondition.notify_allcCs$ddl}|jdtdd|dS)zvWake up all threads waiting on this condition. This method is deprecated, use notify_all() instead. rNz3notifyAll() is deprecated, use notify_all() instead stacklevel)warningswarnDeprecationWarningryr8r}r&r&r' notifyAlls  zCondition.notifyAllrQrG)r^r?r@r_r9rEr`rWrDr[rZr\rqrurxryrr&r&r&r'r s  0  r c@s:eZdZdZd ddZdddZeZd d 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. rGcCs&|dkrtdtt|_||_dS)Nrz$semaphore initial value must be >= 0)ror r_cond_valuer8valuer&r&r'r9s  zSemaphore.__init__TNcCs|s |dur tdd}d}|jM|jdkr=|sn4|dur2|dur(t|}n |t}|dkr2n$|j||jdks|jd8_d}Wd|SWd|SWd|S1sawY|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 acquireFrrGT)rorrrrrq)r8rIrJrLrsr&r&r'rHs8          zSemaphore.acquirecCsb|dkrtd|j|j|7_t|D]}|jqWddS1s*wYdS)zRelease a semaphore, incrementing the internal counter by one or more. When the counter is zero on entry and another thread is waiting for it to become larger than zero again, wake up that thread. rGn must be one or moreN)rorrrangerxr8rvir&r&r'rOs  "zSemaphore.releasecCrPrQrRrSr&r&r'rWrXzSemaphore.__exit__r)TN) r^r?r@r_r9rHr`rOrWr&r&r&r'rs -  rc@s$eZdZdZdddZdddZdS) 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. rGcCst||||_dSrQ)rr9_initial_valuerr&r&r'r9  zBoundedSemaphore.__init__cCsz|dkrtd|j(|j||jkrtd|j|7_t|D]}|jq#WddS1s6wYdS)a>Release a semaphore, incrementing the internal counter by one or more. 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. rGrz!Semaphore released too many timesN)rorrrrrxrr&r&r'rOs   "zBoundedSemaphore.releaseNr)r^r?r@r_r9rOr&r&r&r'rs rc@sJeZdZdZddZddZddZdd Zd d Zd d Z dddZ dS)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 rr_flagr7r&r&r'r9!rzEvent.__init__cCrjrQ)rrEr7r&r&r'rE%zEvent._at_fork_reinitcC|jS)z5Return true if and only if the internal flag is true.)rr7r&r&r'is_set)sz Event.is_setcCs ddl}|jdtdd|S)zyReturn true if and only if the internal flag is true. This method is deprecated, use is_set() instead. rNz+isSet() is deprecated, use is_set() insteadrzr{)r}r~rrrr&r&r'isSet-s z Event.isSetcCs<|jd|_|jWddS1swYdS)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)rrryr7r&r&r'set8s "z Event.setcCs2|j d|_WddS1swYdS)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)rrr7r&r&r'rgCs"z Event.clearNcCsD|j|j}|s|j|}|WdS1swYdS)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)rrrq)r8rJZsignaledr&r&r'rqMs  $z Event.waitrQ) r^r?r@r_r9rErrrrgrqr&r&r&r'rs    rc@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 rr_action_timeout_parties_stater6)r8partiesactionrJr&r&r'r9ws  zBarrier.__init__c Cs|dur|j}|jB||j}|jd7_z&|d|jkr&|n|||W|jd8_|WdS|jd8_|w1sOwYdS)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'. NrG)rr_enterr6r_release_wait_exit)r8rJindexr&r&r'rqs"    z Barrier.waitcCs0|jdvr|j|jdvs|jdkrtdS)NrFrGr)rrrqrr7r&r&r'rs   zBarrier._entercCs6z|jr|d|_|jWdS|)NrG)rrrry_breakr7r&r&r'rszBarrier._releasecs4jfdd|stjdkrtdS)Ncs jdkSr2rr&r7r&r's zBarrier._wait..r)rrurrrr8rJr&r7r'rs  z Barrier._waitcCs0|jdkr|jdvrd|_|jdSdSdS)Nrr)r6rrryr7r&r&r'rs  z Barrier._exitcCsj|j(|jdkr|jdkrd|_n |jdkrd|_nd|_|jWddS1s.wYdS)zReset the barrier to the initial state. Any threads currently waiting will get the BrokenBarrier exception raised. rrFN)rr6rryr7r&r&r'resets    "z Barrier.resetcCs4|j |WddS1swYdS)zPlace the barrier into a 'broken' state. Useful in case of error. Any currently waiting threads and threads attempting to 'wait()' will have BrokenBarrierError raised. N)rrr7r&r&r'aborts "z Barrier.abortcCsd|_|jdS)Nr)rrryr7r&r&r'rszBarrier._breakcCr)z:Return the number of threads required to trip the barrier.)rr7r&r&r'rszBarrier.partiescCs|jdkr|jSdS)z>Return the number of threads currently waiting at the barrier.r)rr6r7r&r&r' n_waitings zBarrier.n_waitingcCs |jdkS)z0Return True if the barrier is in a broken state.rrr7r&r&r'brokens zBarrier.brokenNNrQ)r^r?r@r_r9rqrrrrrrrpropertyrrrr&r&r&r'rns"       rc@s eZdZdS)rN)r^r?r@r&r&r&r'rsrrGcCs |tSrQ)_counter)Z name_templater&r&r'_newnamerhrcCsddtD}t|dS)a! Drop any shutdown locks that don't correspond to running threads anymore. Calling this from time to time avoids an ever-growing _shutdown_locks set when Thread objects are not joined explicitly. See bpo-37788. This must be called with _shutdown_locks_lock acquired. cSsg|]}|s|qSr&)r:).0rfr&r&r' *sz,_maintain_shutdown_locks..N)_shutdown_locksdifference_update)Z to_remover&r&r'_maintain_shutdown_locks s rc@seZdZdZdZ  d8ddddZdd Zd d Zd d ZddZ ddZ ddZ e r0ddZ ddZddZddZddZd9ddZd:d"d#Zed$d%Zejd&d%Zed'd(Ze reed)d*Zd+d,Zed-d.Zejd/d.Zd0d1Zd2d3Zd4d5Zd6d7ZdS);raA class that represents a thread of control. This class can be safely subclassed in a limited fashion. There are two ways to specify the activity: by passing a callable object to the constructor, or by overriding the run() method in a subclass. FNr&)daemoncCs|duri}|r t|}ntd}|dur,z |j}|d|d7}Wn ty+Ynw||_||_||_||_|dur@||_nt j |_d|_ t rMd|_ 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. Nz Thread-%dz ()FT)strrr^rb_target_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)r8grouptargetr<r/r0rZ target_namer&r&r'r9;s:   zThread.__init__cCsD|j|r|jdur|j|jdSdSd|_d|_dSNT)rrErrHr)r8is_aliver&r&r'_reset_internal_locksus    zThread._reset_internal_lockscCs^d}|jr d}||jrd}|jr|d7}|jdur%|d|j7}d|jj|j|fS)NinitialZstartedZstoppedz daemonz %sz <%s(%s, %s)>) rrrrrrr>r^r)r8Zstatusr&r&r'rDs  zThread.__repr__c Cs|jstd|jrtdt |t|<Wdn1s!wYzt|jdWntyKt t|=Wd1sEwYw|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 onceNr&) rrNrr_active_limbo_lock_limbo_start_new_thread _bootstrap Exceptionrqr7r&r&r'starts$     z Thread.startcCsRz!|jdur|j|ji|jW|`|`|`dSW|`|`|`dS|`|`|`w)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)rrrr7r&r&r'runs  z Thread.runcCs,z|WdS|jrtdurYdSrQ)_bootstrap_innerrrr7r&r&r'rs  zThread._bootstrapcC t|_dSrQ)rrr7r&r&r' _set_identrXzThread._set_identcCrrQ)r rr7r&r&r'_set_native_idrXzThread._set_native_idcCsXt|_|j|js*ttt|jWddS1s#wYdSdS)z Set a lock object which will be released by the interpreter when the underlying thread state (see pystate.h) gets deleted. N) _set_sentinelrrHr_shutdown_locks_lockrrrr7r&r&r'_set_tstate_locks "zThread._set_tstate_lockcCs4zt||tr||jt|t|j<t |=Wdn1s)wYt r5t t t r.invoke_excepthook)rrrNexc_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|||_||_|dur|ng|_|dur|ni|_t|_dSrQ)rr9intervalfunctionr/r0rfinished)r8rrr/r0r&r&r'r9Ss  zTimer.__init__cCs|jdS)z)Stop the timer if it hasn't finished yet.N)rrr7r&r&r'cancel[rz Timer.cancelcCs:|j|j|js|j|ji|j|jdSrQ)rrqrrrr/r0rr7r&r&r'r_s z Timer.runr)r^r?r@r_r9r rr&r&r&r'rJs   rc@seZdZddZdS) _MainThreadcCsjtj|ddd||j|tr|t|t |j <WddS1s.wYdS)NZ MainThreadFr<r) rr9rrrrrrrr;rr7r&r&r'r9js  "z_MainThread.__init__N)r^r?r@r9r&r&r&r'r hs r c@s.eZdZddZddZddZd dd ZdS) _DummyThreadcCsftj|tddd|j|tr|t|t |j <WddS1s,wYdS)NzDummy-%dTr ) rr9rrrrrrrr;rr7r&r&r'r9s  "z_DummyThread.__init__cCdSrQr&r7r&r&r'rsz_DummyThread._stopcCsdSrr&r7r&r&r'rr*z_DummyThread.is_aliveNcCr rQr&rr&r&r'rsz_DummyThread.joinrQ)r^r?r@r9rrrr&r&r&r'r }s  r cCs&zttWStytYSw)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. )r;rr=r r&r&r&r'r s    r cCddl}|jdtddtS)zReturn the current Thread object, corresponding to the caller's thread of control. This function is deprecated, use current_thread() instead. rNz;currentThread() is deprecated, use current_thread() insteadrzr{)r}r~rr r}r&r&r' currentThreadrrcCs8tttttWdS1swYdS)zReturn the number of Thread objects currently alive. The returned count is equal to the length of the list returned by enumerate(). N)rrir;rr&r&r&r'rs$rcCr)zxReturn the number of Thread objects currently alive. This function is deprecated, use active_count() instead. rNz7activeCount() is deprecated, use active_count() insteadrzr{)r}r~rrrr&r&r' activeCountrrcCsttttSrQ)listr;valuesrr&r&r&r' _enumeratesrcCs@tttttWdS1swYdS)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)rrr;rrr&r&r&r'r s$r cOs2trtdtj|g|Ri|}t|dS)aCPython internal: register *func* to be called before joining threads. The registered *func* is called with its arguments just before all non-daemon threads are joined in `_shutdown()`. It provides a similar purpose to `atexit.register()`, but its functions are called prior to threading shutdown instead of interpreter shutdown. For similarity to atexit, the registered functions are called in reverse. z$can't register atexit after shutdownN)_SHUTTING_DOWNrN functoolspartial_threading_atexitsrm)r%argr0Zcallr&r&r'_register_atexits r)rcCstjrdSdatj}|tttD]}|q tt t }t Wdn1s2wY|s;dS|D] }| |q=q)zS Wait until the Python thread state of all non-daemon threads get deleted. NT) _main_threadrrrrOrreversedrrrrrgrH)ZtlockZ atexit_callZlocksrfr&r&r' _shutdowns&    rcCr))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 sr )_local)rcCstai}ztt}Wn tyt}Ynw|atat a tBt t }| t |D]}||urF|dt}||_|||<q0|d|q0ttt |WddS1shwYdS)zL Cleanup threading module state that should not exist after a fork. TFN)rrr;rr=r rr3rrrrupdaterrrrrrg)Z new_activeZcurrentZthreadsrrr&r&r' _after_fork.s2         "r register_at_fork)Zafter_in_child)br_os_ossysr_threadrtimerrrZ _weakrefsetr itertoolsrZ_islicerr6 _collectionsrrc ImportError collections__all__start_new_threadr allocate_lockr3rrr rrmrberrorrrr-r r#r,rrrrrr1r.r rrrrrNr__next__rrrr;rrrrrrrrrrr tracebackrrr__excepthook__rrr r r rrrrr rrrrrrr rrZ_threading_localr hasattrr!r&r&r&r's          v;S)X 6   ,5      /  5