Release a semaphore, incrementing the internal counter by one or more. When the counter is zero on entry and another thread is waiting for it to become larger than zero again, wake up that thread. If the number of releases exceeds the number of acquires, raise a Val
(self, n=1)
| 563 | f" value={self._value}/{self._initial_value}>") |
| 564 | |
| 565 | def release(self, n=1): |
| 566 | """Release a semaphore, incrementing the internal counter by one or more. |
| 567 | |
| 568 | When the counter is zero on entry and another thread is waiting for it |
| 569 | to become larger than zero again, wake up that thread. |
| 570 | |
| 571 | If the number of releases exceeds the number of acquires, |
| 572 | raise a ValueError. |
| 573 | |
| 574 | """ |
| 575 | if n < 1: |
| 576 | raise ValueError('n must be one or more') |
| 577 | with self._cond: |
| 578 | if self._value + n > self._initial_value: |
| 579 | raise ValueError("Semaphore released too many times") |
| 580 | self._value += n |
| 581 | self._cond.notify(n) |
| 582 | |
| 583 | |
| 584 | class Event: |