/snap/core18/2979/usr/lib/python3.6/__pycache__
NameSizeModeActions
abc.cpython-36.pyc75150644editdlrm
aifc.cpython-36.pyc259430644editdlrm
antigravity.cpython-36.pyc7790644editdlrm
argparse.cpython-36.pyc604560644editdlrm
ast.cpython-36.pyc117040644editdlrm
asynchat.cpython-36.pyc68150644editdlrm
asyncore.cpython-36.pyc158380644editdlrm
base64.cpython-36.pyc170590644editdlrm
bdb.cpython-36.pyc170330644editdlrm
binhex.cpython-36.pyc120860644editdlrm
bisect.cpython-36.pyc26760644editdlrm
bz2.cpython-36.pyc112820644editdlrm
calendar.cpython-36.pyc258820644editdlrm
cgi.cpython-36.pyc284160644editdlrm
cgitb.cpython-36.pyc100800644editdlrm
chunk.cpython-36.pyc49000644editdlrm
cmd.cpython-36.pyc125750644editdlrm
code.cpython-36.pyc98360644editdlrm
codecs.cpython-36.pyc339000644editdlrm
codeop.cpython-36.pyc62700644editdlrm
colorsys.cpython-36.pyc33110644editdlrm
compileall.cpython-36.pyc82780644editdlrm
configparser.cpython-36.pyc452440644editdlrm
contextlib.cpython-36.pyc111580644editdlrm
copy.cpython-36.pyc70790644editdlrm
copyreg.cpython-36.pyc42440644editdlrm
cProfile.cpython-36.pyc42940644editdlrm
crypt.cpython-36.pyc22420644editdlrm
csv.cpython-36.pyc118550644editdlrm
datetime.cpython-36.pyc545110644editdlrm
decimal.cpython-36.pyc3510644editdlrm
difflib.cpython-36.pyc596420644editdlrm
dis.cpython-36.pyc141810644editdlrm
doctest.cpython-36.pyc755890644editdlrm
dummy_threading.cpython-36.pyc11020644editdlrm
enum.cpython-36.pyc234530644editdlrm
filecmp.cpython-36.pyc83050644editdlrm
fileinput.cpython-36.pyc131520644editdlrm
fnmatch.cpython-36.pyc28740644editdlrm
formatter.cpython-36.pyc175790644editdlrm
fractions.cpython-36.pyc184260644editdlrm
ftplib.cpython-36.pyc283570644editdlrm
functools.cpython-36.pyc240620644editdlrm
genericpath.cpython-36.pyc37260644editdlrm
getopt.cpython-36.pyc62170644editdlrm
getpass.cpython-36.pyc41770644editdlrm
gettext.cpython-36.pyc143060644editdlrm
glob.cpython-36.pyc42590644editdlrm
gzip.cpython-36.pyc162260644editdlrm
hashlib.cpython-36.pyc66920644editdlrm
heapq.cpython-36.pyc142920644editdlrm
hmac.cpython-36.pyc48360644editdlrm
imaplib.cpython-36.pyc421380644editdlrm
imghdr.cpython-36.pyc41500644editdlrm
imp.cpython-36.pyc96960644editdlrm
inspect.cpython-36.pyc797390644editdlrm
io.cpython-36.pyc33870644editdlrm
ipaddress.cpython-36.pyc623860644editdlrm
keyword.cpython-36.pyc17650644editdlrm
linecache.cpython-36.pyc37780644editdlrm
locale.cpython-36.pyc340300644editdlrm
lzma.cpython-36.pyc119920644editdlrm
macpath.cpython-36.pyc56410644editdlrm
macurl2path.cpython-36.pyc18670644editdlrm
mailbox.cpython-36.pyc637520644editdlrm
mailcap.cpython-36.pyc72090644editdlrm
mimetypes.cpython-36.pyc155530644editdlrm
modulefinder.cpython-36.pyc153660644editdlrm
netrc.cpython-36.pyc38360644editdlrm
nntplib.cpython-36.pyc337800644editdlrm
ntpath.cpython-36.pyc131900644editdlrm
nturl2path.cpython-36.pyc14990644editdlrm
numbers.cpython-36.pyc121420644editdlrm
opcode.cpython-36.pyc54130644editdlrm
operator.cpython-36.pyc139130644editdlrm
optparse.cpython-36.pyc480540644editdlrm
os.cpython-36.pyc296280644editdlrm
pathlib.cpython-36.pyc420070644editdlrm
pdb.cpython-36.pyc460940644editdlrm
pickle.cpython-36.pyc426910644editdlrm
pickletools.cpython-36.pyc660200644editdlrm
pipes.cpython-36.pyc78080644editdlrm
pkgutil.cpython-36.pyc162610644editdlrm
platform.cpython-36.pyc291970644editdlrm
plistlib.cpython-36.pyc280550644editdlrm
poplib.cpython-36.pyc133290644editdlrm
posixpath.cpython-36.pyc104560644editdlrm
pprint.cpython-36.pyc158240644editdlrm
profile.cpython-36.pyc139010644editdlrm
pstats.cpython-36.pyc218570644editdlrm
pty.cpython-36.pyc38610644editdlrm
pyclbr.cpython-36.pyc83650644editdlrm
pydoc.cpython-36.pyc837750644editdlrm
py_compile.cpython-36.pyc65440644editdlrm
queue.cpython-36.pyc87550644editdlrm
quopri.cpython-36.pyc57730644editdlrm
random.cpython-36.pyc193300644editdlrm
re.cpython-36.pyc140580644editdlrm
reprlib.cpython-36.pyc54000644editdlrm
rlcompleter.cpython-36.pyc57800644editdlrm
runpy.cpython-36.pyc79820644editdlrm
sched.cpython-36.pyc65640644editdlrm
secrets.cpython-36.pyc21620644editdlrm
selectors.cpython-36.pyc176970644editdlrm
shelve.cpython-36.pyc94580644editdlrm
shlex.cpython-36.pyc69700644editdlrm
shutil.cpython-36.pyc307040644editdlrm
signal.cpython-36.pyc25150644editdlrm
site.cpython-36.pyc165600644editdlrm
sitecustomize.cpython-36.pyc2120644editdlrm
smtpd.cpython-36.pyc266830644editdlrm
smtplib.cpython-36.pyc353400644editdlrm
sndhdr.cpython-36.pyc69130644editdlrm
socket.cpython-36.pyc220130644editdlrm
socketserver.cpython-36.pyc242500644editdlrm
sre_compile.cpython-36.pyc102780644editdlrm
sre_constants.cpython-36.pyc59720644editdlrm
sre_parse.cpython-36.pyc203580644editdlrm
ssl.cpython-36.pyc369390644editdlrm
stat.cpython-36.pyc38510644editdlrm
statistics.cpython-36.pyc181740644editdlrm
string.cpython-36.pyc79640644editdlrm
stringprep.cpython-36.pyc100300644editdlrm
struct.cpython-36.pyc3120644editdlrm
subprocess.cpython-36.pyc354850644editdlrm
sunau.cpython-36.pyc169380644editdlrm
symbol.cpython-36.pyc25170644editdlrm
symtable.cpython-36.pyc104280644editdlrm
sysconfig.cpython-36.pyc159160644editdlrm
tabnanny.cpython-36.pyc69750644editdlrm
tarfile.cpython-36.pyc630850644editdlrm
telnetlib.cpython-36.pyc180970644editdlrm
tempfile.cpython-36.pyc253090644editdlrm
textwrap.cpython-36.pyc136840644editdlrm
this.cpython-36.pyc12650644editdlrm
threading.cpython-36.pyc372340644editdlrm
timeit.cpython-36.pyc116030644editdlrm
token.cpython-36.pyc33200644editdlrm
tokenize.cpython-36.pyc186470644editdlrm
trace.cpython-36.pyc194950644editdlrm
traceback.cpython-36.pyc196460644editdlrm
tracemalloc.cpython-36.pyc172290644editdlrm
tty.cpython-36.pyc10720644editdlrm
turtle.cpython-36.pyc1317510644editdlrm
types.cpython-36.pyc82010644editdlrm
typing.cpython-36.pyc733060644editdlrm
uu.cpython-36.pyc34980644editdlrm
uuid.cpython-36.pyc209180644editdlrm
warnings.cpython-36.pyc132580644editdlrm
wave.cpython-36.pyc178850644editdlrm
weakref.cpython-36.pyc191430644editdlrm
webbrowser.cpython-36.pyc157970644editdlrm
xdrlib.cpython-36.pyc83020644editdlrm
zipapp.cpython-36.pyc55340644editdlrm
zipfile.cpython-36.pyc497280644editdlrm
_bootlocale.cpython-36.pyc9800644editdlrm
_collections_abc.cpython-36.pyc287970644editdlrm
_compat_pickle.cpython-36.pyc65660644editdlrm
_compression.cpython-36.pyc41040644editdlrm
_dummy_thread.cpython-36.pyc48510644editdlrm
_markupbase.cpython-36.pyc79910644editdlrm
_osx_support.cpython-36.pyc96840644editdlrm
_pydecimal.cpython-36.pyc1634020644editdlrm
_pyio.cpython-36.pyc713860644editdlrm
_sitebuiltins.cpython-36.pyc34350644editdlrm
_strptime.cpython-36.pyc159630644editdlrm
_sysconfigdata_m_linux_x86_64-linux-gnu.cpython-36.pyc187790644editdlrm
_threading_local.cpython-36.pyc64250644editdlrm
_weakrefset.cpython-36.pyc78280644editdlrm
__future__.cpython-36.pyc41670644editdlrm
__phello__.foo.cpython-36.pyc1190644editdlrm
Edit: /snap/core18/2979/usr/lib/python3.6/__pycache__/threading.cpython-36.pyc (37234B)
3 Nqi@s|dZddlZddlZddlmZddlmZ ddl m Z ddl m ZmZyddlmZWn ek rxddlmZYnXdd d d d d dddddddddddddddgZejZejZejZejZejZy ejZ Wne!k rdZ YnXej"Z"[da#da$ddZ%ddZ&eZ'ddZGd d!d!Z(e(Z)Gd"d d Z*Gd#ddZ+Gd$dde+Z,Gd%ddZ-Gd&ddZ.Gd'dde/Z0ej1Z2e2d@d)d*Z3ea4iZ5iZ6e Z7Gd+ddZ8Gd,dde8Z9Gd-d.d.e8Z:Gd/d0d0e8Z;d1d Ze>Z?d3d4Z@d5d ZAdd6lmBZBe:aCd7d8ZDd9d:ZEd;d ZFyddd?ZJdS)Az;Thread module emulating a subset of Java's threading model.N) monotonic) format_exc)WeakSet)islicecount)deque get_ident active_count Conditioncurrent_thread enumerate main_thread TIMEOUT_MAXEventLockRLock SemaphoreBoundedSemaphoreThreadBarrierBrokenBarrierErrorTimer ThreadError setprofilesettracelocal stack_sizecCs|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_hook)funcr/usr/lib/python3.6/threading.pyr2scCs|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_hook)rrrr r<scOstdkrt||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)argskwargsrrr rJs  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|_dS)Nr)_allocate_lock_block_owner_count)selfrrr __init__asz_RLock.__init__cCs^|j}yt|j}Wntk r(YnXd|jjr:dnd|jj|jj||j t t |fS)Nz)<%s %s.%s object owner=%r count=%d at %s>lockedZunlocked) r)_activenameKeyErrorr(r- __class__ __module__ __qualname__r*hexid)r+ownerrrr __repr__fsz_RLock.__repr__TcCsDt}|j|kr"|jd7_dS|jj||}|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. r8)rr)r*r(acquire)r+blockingtimeoutmercrrr r9us z_RLock.acquirecCs<|jtkrtd|jd|_}|s8d|_|jjdS)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. zcannot release un-acquired lockr8N)r)r RuntimeErrorr*r(release)r+rrrr r?s  z_RLock.releasecCs |jdS)N)r?)r+tvtbrrr __exit__sz_RLock.__exit__cCs|jj|\|_|_dS)N)r(r9r*r))r+staterrr _acquire_restores z_RLock._acquire_restorecCs<|jdkrtd|j}d|_|j}d|_|jj||fS)Nrzcannot release un-acquired lock)r*r>r)r(r?)r+rr6rrr _release_saves  z_RLock._release_savecCs |jtkS)N)r)r)r+rrr _is_ownedsz_RLock._is_ownedN)TrH) __name__r2r3__doc__r,r7r9 __enter__r?rCrErFrGrrrr r&Ws $ 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|_y |j|_Wntk rDYnXy |j|_Wntk rfYnXy |j|_Wntk rYnXt|_ dS)N) r_lockr9r?rFAttributeErrorrErG_deque_waiters)r+lockrrr r,s$   zCondition.__init__cCs |jjS)N)rLrK)r+rrr rKszCondition.__enter__cGs |jj|S)N)rLrC)r+r$rrr rCszCondition.__exit__cCsd|jt|jfS)Nz)rLlenrO)r+rrr r7szCondition.__repr__cCs|jjdS)N)rLr?)r+rrr rFszCondition._release_savecCs|jjdS)N)rLr9)r+xrrr rEszCondition._acquire_restorecCs"|jjdr|jjdSdSdS)NrFT)rLr9r?)r+rrr rGs  zCondition._is_ownedcCs|jstdt}|j|jj||j}d}z:|dkrN|jd}n |dkrd|jd|}n |jd}|S|j||sy|jj|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) rGr>r'r9rOappendrFrEremove ValueError)r+r;waiterZ saved_stateZgotitrrr waits*   zCondition.waitcCs\d}|}|}xH|sV|dk rD|dkr0t|}n|t}|dkrDP|j||}qW|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)_timerW)r+Z predicater;endtimeZwaittimeresultrrr wait_for7s    zCondition.wait_forr8c Csj|jstd|j}tt||}|s,dSx8|D]0}|jy|j|Wq2tk r`Yq2Xq2WdS)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)rGr>rOrN_islicer?rTrU)r+nZ all_waitersZwaiters_to_notifyrVrrr notifyNs  zCondition.notifycCs|jt|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)r^rQrO)r+rrr notify_alleszCondition.notify_all)N)N)N)r8)rIr2r3rJr,rKrCr7rFrErGrWr[r^r_Z notifyAllrrrr 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. r8cCs&|dkrtdtt|_||_dS)Nrz$semaphore initial value must be >= 0)rUr r_cond_value)r+valuerrr r,}s zSemaphore.__init__TNc Cs| r|dk rtdd}d}|jjxb|jdkrv|s8P|dk rh|dkrTt|}n|t}|dkrhP|jj|q(W|jd8_d}WdQRX|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 acquireFrr8T)rUr`rarXrW)r+r:r;r=rYrrr r9s$   zSemaphore.acquirec Cs.|j|jd7_|jjWdQRXdS)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. r8N)r`rar^)r+rrr r?szSemaphore.releasecCs |jdS)N)r?)r+r@rArBrrr rCszSemaphore.__exit__)r8)TN) rIr2r3rJr,r9rKr?rCrrrr rqs   - 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. r8cCstj||||_dS)N)rr,_initial_value)r+rbrrr r,s zBoundedSemaphore.__init__c CsB|j2|j|jkrtd|jd7_|jjWdQRXdS)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 timesr8N)r`rarcrUr^)r+rrr r?s  zBoundedSemaphore.releaseN)r8)rIr2r3rJr,r?rrrr 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 rr`_flag)r+rrr r,s zEvent.__init__cCs|jjtdS)N)r`r,r)r+rrr _reset_internal_locksszEvent._reset_internal_lockscCs|jS)z5Return true if and only if the internal flag is true.)rd)r+rrr is_setsz Event.is_setc Cs&|jd|_|jjWdQRXdS)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)r`rdr_)r+rrr setsz Event.setc Cs|j d|_WdQRXdS)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)r`rd)r+rrr clear sz Event.clearNc Cs,|j|j}|s|jj|}|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)r`rdrW)r+r;Zsignaledrrr rWs  z Event.wait)N) rIr2r3rJr,rerfZisSetrgrhrWrrrr 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 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 uses as the default for all subsequent 'wait()' calls. rN)r rr`_action_timeout_parties_stater*)r+partiesactionr;rrr r,?s zBarrier.__init__cCs|dkr|j}|jb|j|j}|jd7_z&|d|jkrL|jn |j||S|jd8_|jXWdQRXdS)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'. Nr8)rjr`_enterr*rk_release_wait_exit)r+r;indexrrr rWOs   z Barrier.waitcCs:x|jdkr|jjqW|jdkr(t|jdks6tdS)Nr8rrH)rHr8)rlr`rWrAssertionError)r+rrr roms   zBarrier._enterc Cs>y"|jr|jd|_|jjWn|jYnXdS)Nr8)rirlr`r__break)r+rrr rpxszBarrier._releasecsBjjfdd|s"jtjdkr0tjdks>tdS)Ncs jdkS)Nr)rlr)r+rr szBarrier._wait..rr8)r`r[rurrlrt)r+r;r)r+r rqs  z Barrier._waitcCs(|jdkr$|jdkr$d|_|jjdS)Nrr8rH)rHr8)r*rlr`r_)r+rrr rrs  z Barrier._exitc CsT|jD|jdkr6|jdkr$d|_q<|jdkrReturn the number of threads currently waiting at the barrier.r)rlr*)r+rrr n_waitings zBarrier.n_waitingcCs |jdkS)z0Return True if the barrier is in a broken state.rwrx)rl)r+rrr brokenszBarrier.broken)NN)N)rIr2r3rJr,rWrorprqrrryrzrupropertyrmr{r|rrrr r6s       c@s eZdZdS)rN)rIr2r3rrrr rs Thread-%dcCs |tS)N)_counter)templaterrr _newnamesrc@seZdZdZdZejZdddfdfddddZddZ d d Z d d Z d dZ ddZ ddZddZddZddZddZd3ddZd5dd Zed!d"Zejd#d"Zed$d%Zd&d'ZeZed(d)Zejd*d)Zd+d,Zd-d.Zd/d0Zd1d2ZdS)6raA 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. FN)daemoncCs|dkstd|dkri}||_t|p,t|_||_||_|dk rN||_n tj |_d|_ d|_ t |_ d|_d|_tj|_tj|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#group argument must be None for nowFT)rt_targetstrr_name_args_kwargs _daemonicr r_ident _tstate_lockr_started _is_stopped _initialized_sysstderr_stderr _danglingadd)r+grouptargetr/r$r%rrrr r,s" zThread.__init__cCs(|jj|r|jn d|_d|_dS)NT)rre_set_tstate_lockrr)r+is_aliverrr re"s   zThread._reset_internal_lockscCsl|jstdd}|jjr d}|j|jr2d}|jr@|d7}|jdk rX|d|j7}d|jj |j |fS)Nz Thread.__init__() was not calledinitialZstartedZstoppedz daemonz %sz <%s(%s, %s)>) rrtrrfrrrrr1rIr)r+Zstatusrrr r7.s  zThread.__repr__cCs|jstd|jjr tdt|t|<WdQRXyt|jfWn,tk rtt t|=WdQRXYnX|jj 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 onceN) rr>rrf_active_limbo_lock_limbo_start_new_thread _bootstrap ExceptionrW)r+rrr start<s  z Thread.startc Cs.z|jr|j|j|jWd|`|`|`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)rrr)r+rrr runUs z Thread.runc Cs2y |jWn |jr&tdkr&dSYnXdS)N)_bootstrap_innerrr)r+rrr rfs  zThread._bootstrapcCs t|_dS)N)rr)r+rrr _set_identzszThread._set_identcCst|_|jjdS)z Set a lock object which will be released by the interpreter when the underlying thread state (see pystate.h) gets deleted. N) _set_sentinelrr9)r+rrr r}szThread._set_tstate_lockc2CszT|j|j|jjt|t|j<t|=WdQRXtrLt j tt rZt j t zy |j Wntk r|Ynt rt jdk rtd|jtft jdn|jdk rH|j\}}}zxtd|jd|jdtd|jdx6|r$td|jjj|j|jjjf|jd|j}qWtd||f|jdWd~~~XYnXWdXWdt y tt=Wn YnXWdQRXXdS)NzException in thread %s: %s)filezException in thread z2 (most likely raised during interpreter shutdown):z"Traceback (most recent call last):z File "%s", line %s, in %sz%s: %s)rrrrgrr.rrr!rrrrr SystemExitrprintr/ _format_excr _exc_infotb_framef_code co_filename tb_linenoco_nametb_nextr)r+exc_type exc_valueZexc_tbrrr rsT         zThread._bootstrap_innercCs,|j}|dk r|j std|_d|_dS)NT)rr-rtr)r+rPrrr _stops z Thread._stopcCsByttt=WdQRXWn tk r<dtjkr8YnXdS)zARemove current thread from the dict of currently running threads.NZdummy_threading)rr.rr0rmodules)r+rrr _deletes  zThread._deletecCsZ|jstd|jjs td|tkr2td|dkrD|jn|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 isAlive() 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. zThread.__init__() not calledz'cannot join thread before it is startedzcannot join current threadNr)r;)rr>rrfr _wait_for_tstate_lockmax)r+r;rrr joins   z Thread.joinTr8cCs:|j}|dkr|js6tn|j||r6|j|jdS)N)rrrtr9r?r)r+blockr;rPrrr r&s   zThread._wait_for_tstate_lockcCs|jstd|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. zThread.__init__() not called)rrtr)r+rrr r/4sz Thread.namecCs|jstdt||_dS)NzThread.__init__() not called)rrtrr)r+r/rrr r/?scCs|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. zThread.__init__() not called)rrtr)r+rrr identDs z Thread.identcCs6|jstd|js |jj r$dS|jd|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. zThread.__init__() not calledF)rrtrrrfr)r+rrr rPs  zThread.is_alivecCs|jstd|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 no alive non-daemon threads are left. zThread.__init__() not called)rrtr)r+rrr r`s z Thread.daemoncCs*|jstd|jjr td||_dS)NzThread.__init__() not calledz)cannot set daemon status of active thread)rr>rrfr)r+daemonicrrr rps  cCs|jS)N)r)r+rrr isDaemonxszThread.isDaemoncCs ||_dS)N)r)r+rrrr setDaemon{szThread.setDaemoncCs|jS)N)r/)r+rrr getName~szThread.getNamecCs ||_dS)N)r/)r+r/rrr setNameszThread.setName)NrH)TrH) rIr2r3rJrrexc_inforr,rer7rrrrrrrrrrr}r/setterrrZisAliverrrrrrrrr rs8, A# &    c@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 NcCsFtj|||_||_|dk r"|ng|_|dk r4|ni|_t|_dS)N)rr,intervalfunctionr$r%rfinished)r+rrr$r%rrr r,s  zTimer.__init__cCs|jjdS)z)Stop the timer if it hasn't finished yet.N)rrg)r+rrr cancelsz Timer.cancelcCs6|jj|j|jjs(|j|j|j|jjdS)N)rrWrrfrr$r%rg)r+rrr rs z Timer.run)NN)rIr2r3rJr,rrrrrr rs c@seZdZddZdS) _MainThreadc CsHtj|ddd|j|jj|jt|t|j<WdQRXdS)NZ MainThreadF)r/r) rr,rrrgrrr.r)r+rrr r,s  z_MainThread.__init__N)rIr2r3r,rrrr rsrc@s.eZdZddZddZddZd dd ZdS) _DummyThreadc CsDtj|tddd|jj|jt|t|j<WdQRXdS)NzDummy-%dT)r/r) rr,rrrgrrr.r)r+rrr r,s  z_DummyThread.__init__cCsdS)Nr)r+rrr rsz_DummyThread._stopcCs|j r|jjstdS)NT)rrrfrt)r+rrr rsz_DummyThread.is_aliveNcCsds tddS)NFzcannot join a dummy thread)rt)r+r;rrr rsz_DummyThread.join)N)rIr2r3r,rrrrrrr rsrc Cs&y ttStk r tSXdS)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)r.rr0rrrrr r s c Cs tttttSQRXdS)zReturn the number of Thread objects currently alive. The returned count is equal to the length of the list returned by enumerate(). N)rrQr.rrrrr r scCsttjttjS)N)listr.valuesrrrrr _enumeratesrc Cs(tttjttjSQRXdS)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.rrrrrr r s)rcCsPtj}|dk st|jst|jtjt}x|rJ|jt}q6WdS)N) _main_threadrrtr-r?r_pickSomeNonDaemonThreadr)Ztlockr@rrr _shutdowns  rcCs(x"tD]}|j r|jr|SqWdS)N)r rr)r@rrr rs rcCstS)zReturn the main thread object. In normal conditions, the main thread is the thread from which the Python interpreter was started. )rrrrr r s)_local)rc Cstai}t}|attt}|jtxF|D]>}||kr`|jdt }||_ |||<q4|jd|j q4Wt j tj tj|ttdkstWdQRXdS)NTFr8)r'rr rrgrupdaterrerrrrrhr.rQrt)Z new_activeZcurrentZthreadsZthreadrrrr _after_fork(s&        r)r~)KrJsysr_threadZtimerrX tracebackrr _weakrefsetr itertoolsrr\rr* _collectionsrrN ImportError collections__all__start_new_threadr allocate_lockr'rrerrorrrr"rMrrr!rrrr&r#r rrrrr>r__next__rrrr.rrrrrrr Z currentThreadr Z activeCountrr rrrrr rrZ_threading_localrrrrr s           q'P&O '