Commit 0aa10145 authored by Denis Bilenko's avatar Denis Bilenko

add BoundedSemaphore (from stdlib's threading)

parent a0083484
......@@ -152,6 +152,23 @@ class DummySemaphore(object):
self.release()
class BoundedSemaphore(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."""
def __init__(self, value=1):
Semaphore.__init__(self, value)
self._initial_value = value
def release(self):
if self.counter >= self._initial_value:
raise ValueError, "Semaphore released too many times"
return _Semaphore.release(self)
class RLock(object):
def __init__(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment