summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
diff options
context:
space:
mode:
authorSkip Montanaro <skip@pobox.com>2001-08-20 20:27:58 (GMT)
committerSkip Montanaro <skip@pobox.com>2001-08-20 20:27:58 (GMT)
commite428bb703010317dc6f87c9a1e709dff8e078535 (patch)
treed51c3cf205dddaa487049020176f4073698d3e25 /Lib/threading.py
parenta7fc21baf63e8a95f099ff20bccde7b90c9e2253 (diff)
downloadcpython-e428bb703010317dc6f87c9a1e709dff8e078535.zip
cpython-e428bb703010317dc6f87c9a1e709dff8e078535.tar.gz
cpython-e428bb703010317dc6f87c9a1e709dff8e078535.tar.bz2
Added new BoundedSemaphore class. Closes bug 452836.
Diffstat (limited to 'Lib/threading.py')
-rw-r--r--Lib/threading.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index 004ccb6..268c09c 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -284,6 +284,21 @@ class _Semaphore(_Verbose):
self.__cond.release()
+def BoundedSemaphore(*args, **kwargs):
+ return apply(_BoundedSemaphore, args, kwargs)
+
+class _BoundedSemaphore(_Semaphore):
+ """Semaphore that checks that # releases is <= # acquires"""
+ def __init__(self, value=1, verbose=None):
+ _Semaphore.__init__(self, value, verbose)
+ self._initial_value = value
+
+ def release(self):
+ if self._Semaphore__value >= self._initial_value:
+ raise ValueError, "Semaphore released too many times"
+ return _Semaphore.release(self)
+
+
def Event(*args, **kwargs):
return apply(_Event, args, kwargs)