Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../lib64/python2....
File: threading.py
"""Thread module emulating a subset of Java's threading model."""
[0] Fix | Delete
[1] Fix | Delete
import sys as _sys
[2] Fix | Delete
[3] Fix | Delete
try:
[4] Fix | Delete
import thread
[5] Fix | Delete
except ImportError:
[6] Fix | Delete
del _sys.modules[__name__]
[7] Fix | Delete
raise
[8] Fix | Delete
[9] Fix | Delete
import warnings
[10] Fix | Delete
[11] Fix | Delete
from collections import deque as _deque
[12] Fix | Delete
from itertools import count as _count
[13] Fix | Delete
from time import time as _time, sleep as _sleep
[14] Fix | Delete
from traceback import format_exc as _format_exc
[15] Fix | Delete
[16] Fix | Delete
# Note regarding PEP 8 compliant aliases
[17] Fix | Delete
# This threading model was originally inspired by Java, and inherited
[18] Fix | Delete
# the convention of camelCase function and method names from that
[19] Fix | Delete
# language. While those names are not in any imminent danger of being
[20] Fix | Delete
# deprecated, starting with Python 2.6, the module now provides a
[21] Fix | Delete
# PEP 8 compliant alias for any such method name.
[22] Fix | Delete
# Using the new PEP 8 compliant names also facilitates substitution
[23] Fix | Delete
# with the multiprocessing module, which doesn't provide the old
[24] Fix | Delete
# Java inspired names.
[25] Fix | Delete
[26] Fix | Delete
[27] Fix | Delete
# Rename some stuff so "from threading import *" is safe
[28] Fix | Delete
__all__ = ['activeCount', 'active_count', 'Condition', 'currentThread',
[29] Fix | Delete
'current_thread', 'enumerate', 'Event',
[30] Fix | Delete
'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Thread',
[31] Fix | Delete
'Timer', 'setprofile', 'settrace', 'local', 'stack_size']
[32] Fix | Delete
[33] Fix | Delete
_start_new_thread = thread.start_new_thread
[34] Fix | Delete
_allocate_lock = thread.allocate_lock
[35] Fix | Delete
_get_ident = thread.get_ident
[36] Fix | Delete
ThreadError = thread.error
[37] Fix | Delete
del thread
[38] Fix | Delete
[39] Fix | Delete
[40] Fix | Delete
# sys.exc_clear is used to work around the fact that except blocks
[41] Fix | Delete
# don't fully clear the exception until 3.0.
[42] Fix | Delete
warnings.filterwarnings('ignore', category=DeprecationWarning,
[43] Fix | Delete
module='threading', message='sys.exc_clear')
[44] Fix | Delete
[45] Fix | Delete
# Debug support (adapted from ihooks.py).
[46] Fix | Delete
# All the major classes here derive from _Verbose. We force that to
[47] Fix | Delete
# be a new-style class so that all the major classes here are new-style.
[48] Fix | Delete
# This helps debugging (type(instance) is more revealing for instances
[49] Fix | Delete
# of new-style classes).
[50] Fix | Delete
[51] Fix | Delete
_VERBOSE = False
[52] Fix | Delete
[53] Fix | Delete
if __debug__:
[54] Fix | Delete
[55] Fix | Delete
class _Verbose(object):
[56] Fix | Delete
[57] Fix | Delete
def __init__(self, verbose=None):
[58] Fix | Delete
if verbose is None:
[59] Fix | Delete
verbose = _VERBOSE
[60] Fix | Delete
self.__verbose = verbose
[61] Fix | Delete
[62] Fix | Delete
def _note(self, format, *args):
[63] Fix | Delete
if self.__verbose:
[64] Fix | Delete
format = format % args
[65] Fix | Delete
# Issue #4188: calling current_thread() can incur an infinite
[66] Fix | Delete
# recursion if it has to create a DummyThread on the fly.
[67] Fix | Delete
ident = _get_ident()
[68] Fix | Delete
try:
[69] Fix | Delete
name = _active[ident].name
[70] Fix | Delete
except KeyError:
[71] Fix | Delete
name = "<OS thread %d>" % ident
[72] Fix | Delete
format = "%s: %s\n" % (name, format)
[73] Fix | Delete
_sys.stderr.write(format)
[74] Fix | Delete
[75] Fix | Delete
else:
[76] Fix | Delete
# Disable this when using "python -O"
[77] Fix | Delete
class _Verbose(object):
[78] Fix | Delete
def __init__(self, verbose=None):
[79] Fix | Delete
pass
[80] Fix | Delete
def _note(self, *args):
[81] Fix | Delete
pass
[82] Fix | Delete
[83] Fix | Delete
# Support for profile and trace hooks
[84] Fix | Delete
[85] Fix | Delete
_profile_hook = None
[86] Fix | Delete
_trace_hook = None
[87] Fix | Delete
[88] Fix | Delete
def setprofile(func):
[89] Fix | Delete
"""Set a profile function for all threads started from the threading module.
[90] Fix | Delete
[91] Fix | Delete
The func will be passed to sys.setprofile() for each thread, before its
[92] Fix | Delete
run() method is called.
[93] Fix | Delete
[94] Fix | Delete
"""
[95] Fix | Delete
global _profile_hook
[96] Fix | Delete
_profile_hook = func
[97] Fix | Delete
[98] Fix | Delete
def settrace(func):
[99] Fix | Delete
"""Set a trace function for all threads started from the threading module.
[100] Fix | Delete
[101] Fix | Delete
The func will be passed to sys.settrace() for each thread, before its run()
[102] Fix | Delete
method is called.
[103] Fix | Delete
[104] Fix | Delete
"""
[105] Fix | Delete
global _trace_hook
[106] Fix | Delete
_trace_hook = func
[107] Fix | Delete
[108] Fix | Delete
# Synchronization classes
[109] Fix | Delete
[110] Fix | Delete
Lock = _allocate_lock
[111] Fix | Delete
[112] Fix | Delete
def RLock(*args, **kwargs):
[113] Fix | Delete
"""Factory function that returns a new reentrant lock.
[114] Fix | Delete
[115] Fix | Delete
A reentrant lock must be released by the thread that acquired it. Once a
[116] Fix | Delete
thread has acquired a reentrant lock, the same thread may acquire it again
[117] Fix | Delete
without blocking; the thread must release it once for each time it has
[118] Fix | Delete
acquired it.
[119] Fix | Delete
[120] Fix | Delete
"""
[121] Fix | Delete
return _RLock(*args, **kwargs)
[122] Fix | Delete
[123] Fix | Delete
class _RLock(_Verbose):
[124] Fix | Delete
"""A reentrant lock must be released by the thread that acquired it. Once a
[125] Fix | Delete
thread has acquired a reentrant lock, the same thread may acquire it
[126] Fix | Delete
again without blocking; the thread must release it once for each time it
[127] Fix | Delete
has acquired it.
[128] Fix | Delete
"""
[129] Fix | Delete
[130] Fix | Delete
def __init__(self, verbose=None):
[131] Fix | Delete
_Verbose.__init__(self, verbose)
[132] Fix | Delete
self.__block = _allocate_lock()
[133] Fix | Delete
self.__owner = None
[134] Fix | Delete
self.__count = 0
[135] Fix | Delete
[136] Fix | Delete
def __repr__(self):
[137] Fix | Delete
owner = self.__owner
[138] Fix | Delete
try:
[139] Fix | Delete
owner = _active[owner].name
[140] Fix | Delete
except KeyError:
[141] Fix | Delete
pass
[142] Fix | Delete
return "<%s owner=%r count=%d>" % (
[143] Fix | Delete
self.__class__.__name__, owner, self.__count)
[144] Fix | Delete
[145] Fix | Delete
def acquire(self, blocking=1):
[146] Fix | Delete
"""Acquire a lock, blocking or non-blocking.
[147] Fix | Delete
[148] Fix | Delete
When invoked without arguments: if this thread already owns the lock,
[149] Fix | Delete
increment the recursion level by one, and return immediately. Otherwise,
[150] Fix | Delete
if another thread owns the lock, block until the lock is unlocked. Once
[151] Fix | Delete
the lock is unlocked (not owned by any thread), then grab ownership, set
[152] Fix | Delete
the recursion level to one, and return. If more than one thread is
[153] Fix | Delete
blocked waiting until the lock is unlocked, only one at a time will be
[154] Fix | Delete
able to grab ownership of the lock. There is no return value in this
[155] Fix | Delete
case.
[156] Fix | Delete
[157] Fix | Delete
When invoked with the blocking argument set to true, do the same thing
[158] Fix | Delete
as when called without arguments, and return true.
[159] Fix | Delete
[160] Fix | Delete
When invoked with the blocking argument set to false, do not block. If a
[161] Fix | Delete
call without an argument would block, return false immediately;
[162] Fix | Delete
otherwise, do the same thing as when called without arguments, and
[163] Fix | Delete
return true.
[164] Fix | Delete
[165] Fix | Delete
"""
[166] Fix | Delete
me = _get_ident()
[167] Fix | Delete
if self.__owner == me:
[168] Fix | Delete
self.__count = self.__count + 1
[169] Fix | Delete
if __debug__:
[170] Fix | Delete
self._note("%s.acquire(%s): recursive success", self, blocking)
[171] Fix | Delete
return 1
[172] Fix | Delete
rc = self.__block.acquire(blocking)
[173] Fix | Delete
if rc:
[174] Fix | Delete
self.__owner = me
[175] Fix | Delete
self.__count = 1
[176] Fix | Delete
if __debug__:
[177] Fix | Delete
self._note("%s.acquire(%s): initial success", self, blocking)
[178] Fix | Delete
else:
[179] Fix | Delete
if __debug__:
[180] Fix | Delete
self._note("%s.acquire(%s): failure", self, blocking)
[181] Fix | Delete
return rc
[182] Fix | Delete
[183] Fix | Delete
__enter__ = acquire
[184] Fix | Delete
[185] Fix | Delete
def release(self):
[186] Fix | Delete
"""Release a lock, decrementing the recursion level.
[187] Fix | Delete
[188] Fix | Delete
If after the decrement it is zero, reset the lock to unlocked (not owned
[189] Fix | Delete
by any thread), and if any other threads are blocked waiting for the
[190] Fix | Delete
lock to become unlocked, allow exactly one of them to proceed. If after
[191] Fix | Delete
the decrement the recursion level is still nonzero, the lock remains
[192] Fix | Delete
locked and owned by the calling thread.
[193] Fix | Delete
[194] Fix | Delete
Only call this method when the calling thread owns the lock. A
[195] Fix | Delete
RuntimeError is raised if this method is called when the lock is
[196] Fix | Delete
unlocked.
[197] Fix | Delete
[198] Fix | Delete
There is no return value.
[199] Fix | Delete
[200] Fix | Delete
"""
[201] Fix | Delete
if self.__owner != _get_ident():
[202] Fix | Delete
raise RuntimeError("cannot release un-acquired lock")
[203] Fix | Delete
self.__count = count = self.__count - 1
[204] Fix | Delete
if not count:
[205] Fix | Delete
self.__owner = None
[206] Fix | Delete
self.__block.release()
[207] Fix | Delete
if __debug__:
[208] Fix | Delete
self._note("%s.release(): final release", self)
[209] Fix | Delete
else:
[210] Fix | Delete
if __debug__:
[211] Fix | Delete
self._note("%s.release(): non-final release", self)
[212] Fix | Delete
[213] Fix | Delete
def __exit__(self, t, v, tb):
[214] Fix | Delete
self.release()
[215] Fix | Delete
[216] Fix | Delete
# Internal methods used by condition variables
[217] Fix | Delete
[218] Fix | Delete
def _acquire_restore(self, count_owner):
[219] Fix | Delete
count, owner = count_owner
[220] Fix | Delete
self.__block.acquire()
[221] Fix | Delete
self.__count = count
[222] Fix | Delete
self.__owner = owner
[223] Fix | Delete
if __debug__:
[224] Fix | Delete
self._note("%s._acquire_restore()", self)
[225] Fix | Delete
[226] Fix | Delete
def _release_save(self):
[227] Fix | Delete
if __debug__:
[228] Fix | Delete
self._note("%s._release_save()", self)
[229] Fix | Delete
count = self.__count
[230] Fix | Delete
self.__count = 0
[231] Fix | Delete
owner = self.__owner
[232] Fix | Delete
self.__owner = None
[233] Fix | Delete
self.__block.release()
[234] Fix | Delete
return (count, owner)
[235] Fix | Delete
[236] Fix | Delete
def _is_owned(self):
[237] Fix | Delete
return self.__owner == _get_ident()
[238] Fix | Delete
[239] Fix | Delete
[240] Fix | Delete
def Condition(*args, **kwargs):
[241] Fix | Delete
"""Factory function that returns a new condition variable object.
[242] Fix | Delete
[243] Fix | Delete
A condition variable allows one or more threads to wait until they are
[244] Fix | Delete
notified by another thread.
[245] Fix | Delete
[246] Fix | Delete
If the lock argument is given and not None, it must be a Lock or RLock
[247] Fix | Delete
object, and it is used as the underlying lock. Otherwise, a new RLock object
[248] Fix | Delete
is created and used as the underlying lock.
[249] Fix | Delete
[250] Fix | Delete
"""
[251] Fix | Delete
return _Condition(*args, **kwargs)
[252] Fix | Delete
[253] Fix | Delete
class _Condition(_Verbose):
[254] Fix | Delete
"""Condition variables allow one or more threads to wait until they are
[255] Fix | Delete
notified by another thread.
[256] Fix | Delete
"""
[257] Fix | Delete
[258] Fix | Delete
def __init__(self, lock=None, verbose=None):
[259] Fix | Delete
_Verbose.__init__(self, verbose)
[260] Fix | Delete
if lock is None:
[261] Fix | Delete
lock = RLock()
[262] Fix | Delete
self.__lock = lock
[263] Fix | Delete
# Export the lock's acquire() and release() methods
[264] Fix | Delete
self.acquire = lock.acquire
[265] Fix | Delete
self.release = lock.release
[266] Fix | Delete
# If the lock defines _release_save() and/or _acquire_restore(),
[267] Fix | Delete
# these override the default implementations (which just call
[268] Fix | Delete
# release() and acquire() on the lock). Ditto for _is_owned().
[269] Fix | Delete
try:
[270] Fix | Delete
self._release_save = lock._release_save
[271] Fix | Delete
except AttributeError:
[272] Fix | Delete
pass
[273] Fix | Delete
try:
[274] Fix | Delete
self._acquire_restore = lock._acquire_restore
[275] Fix | Delete
except AttributeError:
[276] Fix | Delete
pass
[277] Fix | Delete
try:
[278] Fix | Delete
self._is_owned = lock._is_owned
[279] Fix | Delete
except AttributeError:
[280] Fix | Delete
pass
[281] Fix | Delete
self.__waiters = []
[282] Fix | Delete
[283] Fix | Delete
def __enter__(self):
[284] Fix | Delete
return self.__lock.__enter__()
[285] Fix | Delete
[286] Fix | Delete
def __exit__(self, *args):
[287] Fix | Delete
return self.__lock.__exit__(*args)
[288] Fix | Delete
[289] Fix | Delete
def __repr__(self):
[290] Fix | Delete
return "<Condition(%s, %d)>" % (self.__lock, len(self.__waiters))
[291] Fix | Delete
[292] Fix | Delete
def _release_save(self):
[293] Fix | Delete
self.__lock.release() # No state to save
[294] Fix | Delete
[295] Fix | Delete
def _acquire_restore(self, x):
[296] Fix | Delete
self.__lock.acquire() # Ignore saved state
[297] Fix | Delete
[298] Fix | Delete
def _is_owned(self):
[299] Fix | Delete
# Return True if lock is owned by current_thread.
[300] Fix | Delete
# This method is called only if __lock doesn't have _is_owned().
[301] Fix | Delete
if self.__lock.acquire(0):
[302] Fix | Delete
self.__lock.release()
[303] Fix | Delete
return False
[304] Fix | Delete
else:
[305] Fix | Delete
return True
[306] Fix | Delete
[307] Fix | Delete
def wait(self, timeout=None, balancing=True):
[308] Fix | Delete
"""Wait until notified or until a timeout occurs.
[309] Fix | Delete
[310] Fix | Delete
If the calling thread has not acquired the lock when this method is
[311] Fix | Delete
called, a RuntimeError is raised.
[312] Fix | Delete
[313] Fix | Delete
This method releases the underlying lock, and then blocks until it is
[314] Fix | Delete
awakened by a notify() or notifyAll() call for the same condition
[315] Fix | Delete
variable in another thread, or until the optional timeout occurs. Once
[316] Fix | Delete
awakened or timed out, it re-acquires the lock and returns.
[317] Fix | Delete
[318] Fix | Delete
When the timeout argument is present and not None, it should be a
[319] Fix | Delete
floating point number specifying a timeout for the operation in seconds
[320] Fix | Delete
(or fractions thereof).
[321] Fix | Delete
[322] Fix | Delete
When the underlying lock is an RLock, it is not released using its
[323] Fix | Delete
release() method, since this may not actually unlock the lock when it
[324] Fix | Delete
was acquired multiple times recursively. Instead, an internal interface
[325] Fix | Delete
of the RLock class is used, which really unlocks it even when it has
[326] Fix | Delete
been recursively acquired several times. Another internal interface is
[327] Fix | Delete
then used to restore the recursion level when the lock is reacquired.
[328] Fix | Delete
[329] Fix | Delete
"""
[330] Fix | Delete
if not self._is_owned():
[331] Fix | Delete
raise RuntimeError("cannot wait on un-acquired lock")
[332] Fix | Delete
waiter = _allocate_lock()
[333] Fix | Delete
waiter.acquire()
[334] Fix | Delete
self.__waiters.append(waiter)
[335] Fix | Delete
saved_state = self._release_save()
[336] Fix | Delete
try: # restore state no matter what (e.g., KeyboardInterrupt)
[337] Fix | Delete
if timeout is None:
[338] Fix | Delete
waiter.acquire()
[339] Fix | Delete
if __debug__:
[340] Fix | Delete
self._note("%s.wait(): got it", self)
[341] Fix | Delete
else:
[342] Fix | Delete
# Balancing act: We can't afford a pure busy loop, so we
[343] Fix | Delete
# have to sleep; but if we sleep the whole timeout time,
[344] Fix | Delete
# we'll be unresponsive. The scheme here sleeps very
[345] Fix | Delete
# little at first, longer as time goes on, but never longer
[346] Fix | Delete
# than 20 times per second (or the timeout time remaining).
[347] Fix | Delete
endtime = _time() + timeout
[348] Fix | Delete
delay = 0.0005 # 500 us -> initial delay of 1 ms
[349] Fix | Delete
while True:
[350] Fix | Delete
gotit = waiter.acquire(0)
[351] Fix | Delete
if gotit:
[352] Fix | Delete
break
[353] Fix | Delete
remaining = min(endtime - _time(), timeout)
[354] Fix | Delete
if remaining <= 0:
[355] Fix | Delete
break
[356] Fix | Delete
if balancing:
[357] Fix | Delete
delay = min(delay * 2, remaining, 0.05)
[358] Fix | Delete
else:
[359] Fix | Delete
delay = remaining
[360] Fix | Delete
endtime = _time() + remaining
[361] Fix | Delete
_sleep(delay)
[362] Fix | Delete
if not gotit:
[363] Fix | Delete
if __debug__:
[364] Fix | Delete
self._note("%s.wait(%s): timed out", self, timeout)
[365] Fix | Delete
try:
[366] Fix | Delete
self.__waiters.remove(waiter)
[367] Fix | Delete
except ValueError:
[368] Fix | Delete
pass
[369] Fix | Delete
else:
[370] Fix | Delete
if __debug__:
[371] Fix | Delete
self._note("%s.wait(%s): got it", self, timeout)
[372] Fix | Delete
finally:
[373] Fix | Delete
self._acquire_restore(saved_state)
[374] Fix | Delete
[375] Fix | Delete
def notify(self, n=1):
[376] Fix | Delete
"""Wake up one or more threads waiting on this condition, if any.
[377] Fix | Delete
[378] Fix | Delete
If the calling thread has not acquired the lock when this method is
[379] Fix | Delete
called, a RuntimeError is raised.
[380] Fix | Delete
[381] Fix | Delete
This method wakes up at most n of the threads waiting for the condition
[382] Fix | Delete
variable; it is a no-op if no threads are waiting.
[383] Fix | Delete
[384] Fix | Delete
"""
[385] Fix | Delete
if not self._is_owned():
[386] Fix | Delete
raise RuntimeError("cannot notify on un-acquired lock")
[387] Fix | Delete
__waiters = self.__waiters
[388] Fix | Delete
waiters = __waiters[:n]
[389] Fix | Delete
if not waiters:
[390] Fix | Delete
if __debug__:
[391] Fix | Delete
self._note("%s.notify(): no waiters", self)
[392] Fix | Delete
return
[393] Fix | Delete
self._note("%s.notify(): notifying %d waiter%s", self, n,
[394] Fix | Delete
n!=1 and "s" or "")
[395] Fix | Delete
for waiter in waiters:
[396] Fix | Delete
waiter.release()
[397] Fix | Delete
try:
[398] Fix | Delete
__waiters.remove(waiter)
[399] Fix | Delete
except ValueError:
[400] Fix | Delete
pass
[401] Fix | Delete
[402] Fix | Delete
def notifyAll(self):
[403] Fix | Delete
"""Wake up all threads waiting on this condition.
[404] Fix | Delete
[405] Fix | Delete
If the calling thread has not acquired the lock when this method
[406] Fix | Delete
is called, a RuntimeError is raised.
[407] Fix | Delete
[408] Fix | Delete
"""
[409] Fix | Delete
self.notify(len(self.__waiters))
[410] Fix | Delete
[411] Fix | Delete
notify_all = notifyAll
[412] Fix | Delete
[413] Fix | Delete
[414] Fix | Delete
def Semaphore(*args, **kwargs):
[415] Fix | Delete
"""A factory function that returns a new semaphore.
[416] Fix | Delete
[417] Fix | Delete
Semaphores manage a counter representing the number of release() calls minus
[418] Fix | Delete
the number of acquire() calls, plus an initial value. The acquire() method
[419] Fix | Delete
blocks if necessary until it can return without making the counter
[420] Fix | Delete
negative. If not given, value defaults to 1.
[421] Fix | Delete
[422] Fix | Delete
"""
[423] Fix | Delete
return _Semaphore(*args, **kwargs)
[424] Fix | Delete
[425] Fix | Delete
class _Semaphore(_Verbose):
[426] Fix | Delete
"""Semaphores manage a counter representing the number of release() calls
[427] Fix | Delete
minus the number of acquire() calls, plus an initial value. The acquire()
[428] Fix | Delete
method blocks if necessary until it can return without making the counter
[429] Fix | Delete
negative. If not given, value defaults to 1.
[430] Fix | Delete
[431] Fix | Delete
"""
[432] Fix | Delete
[433] Fix | Delete
# After Tim Peters' semaphore class, but not quite the same (no maximum)
[434] Fix | Delete
[435] Fix | Delete
def __init__(self, value=1, verbose=None):
[436] Fix | Delete
if value < 0:
[437] Fix | Delete
raise ValueError("semaphore initial value must be >= 0")
[438] Fix | Delete
_Verbose.__init__(self, verbose)
[439] Fix | Delete
self.__cond = Condition(Lock())
[440] Fix | Delete
self.__value = value
[441] Fix | Delete
[442] Fix | Delete
def acquire(self, blocking=1):
[443] Fix | Delete
"""Acquire a semaphore, decrementing the internal counter by one.
[444] Fix | Delete
[445] Fix | Delete
When invoked without arguments: if the internal counter is larger than
[446] Fix | Delete
zero on entry, decrement it by one and return immediately. If it is zero
[447] Fix | Delete
on entry, block, waiting until some other thread has called release() to
[448] Fix | Delete
make it larger than zero. This is done with proper interlocking so that
[449] Fix | Delete
if multiple acquire() calls are blocked, release() will wake exactly one
[450] Fix | Delete
of them up. The implementation may pick one at random, so the order in
[451] Fix | Delete
which blocked threads are awakened should not be relied on. There is no
[452] Fix | Delete
return value in this case.
[453] Fix | Delete
[454] Fix | Delete
When invoked with blocking set to true, do the same thing as when called
[455] Fix | Delete
without arguments, and return true.
[456] Fix | Delete
[457] Fix | Delete
When invoked with blocking set to false, do not block. If a call without
[458] Fix | Delete
an argument would block, return false immediately; otherwise, do the
[459] Fix | Delete
same thing as when called without arguments, and return true.
[460] Fix | Delete
[461] Fix | Delete
"""
[462] Fix | Delete
rc = False
[463] Fix | Delete
with self.__cond:
[464] Fix | Delete
while self.__value == 0:
[465] Fix | Delete
if not blocking:
[466] Fix | Delete
break
[467] Fix | Delete
if __debug__:
[468] Fix | Delete
self._note("%s.acquire(%s): blocked waiting, value=%s",
[469] Fix | Delete
self, blocking, self.__value)
[470] Fix | Delete
self.__cond.wait()
[471] Fix | Delete
else:
[472] Fix | Delete
self.__value = self.__value - 1
[473] Fix | Delete
if __debug__:
[474] Fix | Delete
self._note("%s.acquire: success, value=%s",
[475] Fix | Delete
self, self.__value)
[476] Fix | Delete
rc = True
[477] Fix | Delete
return rc
[478] Fix | Delete
[479] Fix | Delete
__enter__ = acquire
[480] Fix | Delete
[481] Fix | Delete
def release(self):
[482] Fix | Delete
"""Release a semaphore, incrementing the internal counter by one.
[483] Fix | Delete
[484] Fix | Delete
When the counter is zero on entry and another thread is waiting for it
[485] Fix | Delete
to become larger than zero again, wake up that thread.
[486] Fix | Delete
[487] Fix | Delete
"""
[488] Fix | Delete
with self.__cond:
[489] Fix | Delete
self.__value = self.__value + 1
[490] Fix | Delete
if __debug__:
[491] Fix | Delete
self._note("%s.release: success, value=%s",
[492] Fix | Delete
self, self.__value)
[493] Fix | Delete
self.__cond.notify()
[494] Fix | Delete
[495] Fix | Delete
def __exit__(self, t, v, tb):
[496] Fix | Delete
self.release()
[497] Fix | Delete
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function