| 252 | return '<%s(%s, %s)>' % (self.__class__.__name__, self._lock, num_waiters) |
| 253 | |
| 254 | def wait(self, timeout=None): |
| 255 | assert self._lock._semlock._is_mine(), \ |
| 256 | 'must acquire() condition before using wait()' |
| 257 | |
| 258 | # indicate that this thread is going to sleep |
| 259 | self._sleeping_count.release() |
| 260 | |
| 261 | # release lock |
| 262 | count = self._lock._semlock._count() |
| 263 | for i in range(count): |
| 264 | self._lock.release() |
| 265 | |
| 266 | try: |
| 267 | # wait for notification or timeout |
| 268 | return self._wait_semaphore.acquire(True, timeout) |
| 269 | finally: |
| 270 | # indicate that this thread has woken |
| 271 | self._woken_count.release() |
| 272 | |
| 273 | # reacquire lock |
| 274 | for i in range(count): |
| 275 | self._lock.acquire() |
| 276 | |
| 277 | def notify(self, n=1): |
| 278 | assert self._lock._semlock._is_mine(), 'lock is not owned' |