[Python-checkins] CVS: python/dist/src/Lib threading.py,1.16,1.17
Skip Montanaro
montanaro@users.sourceforge.net
Mon, 20 Aug 2001 13:28:00 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv5936
Modified Files:
threading.py
Log Message:
Added new BoundedSemaphore class. Closes bug 452836.
Index: threading.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/threading.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** threading.py 2001/08/19 05:53:47 1.16
--- threading.py 2001/08/20 20:27:58 1.17
***************
*** 285,288 ****
--- 285,303 ----
+ 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)