Message198959
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 ;-) |
|
Date |
User |
Action |
Args |
2013-10-04 17:29:17 | tim.peters | set | recipients:
+ tim.peters, sbt |
2013-10-04 17:29:17 | tim.peters | set | messageid: <1380907757.04.0.265944466599.issue19158@psf.upfronthosting.co.za> |
2013-10-04 17:29:17 | tim.peters | link | issue19158 messages |
2013-10-04 17:29:16 | tim.peters | create | |
|