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