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