Tim Peters added the comment:

Richard, that's a strange argument ;-)  Since, e.g., a BoundedSemaphore(1) is 
semantically equivalent to a mutex, it's like saying some_mutex.release() 
usually raises an exception if the mutex isn't held at the time - but maybe it 
won't.  If the docs _say_ it's not reliable, fair enough.  But they don't say 
that.  When a thread gimmick is _intended_ to be probabilistic, the docs say so 
(e.g., Queue.qsize()).

Probably would have been better if a bounded=False optional argument to 
Semaphore.__init__() had been added, rather than creating a new 
BoundedSemaphore class.  But, as is, it could easily be made reliable:

1. Change Semaphore's condition variable to use an RLock (instead of the 
current Lock).

2. Stuff the body of BoundedSemaphore.release() in a `with self._cond:` block.

Curiously, there doesn't appear to be a test that BoundedSemaphore.release ever 
raises ValueError.  So I'll readily agree that nobody ever took this seriously 
;-)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue19158>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to