Wait until notified. If the calling coroutine has not acquired the lock when this method is called, a RuntimeError is raised. This method releases the underlying lock, and then blocks until it is awakened by a notify() or notify_all() call for the sam
(self)
| 246 | return f'<{res[1:-1]} [{extra}]>' |
| 247 | |
| 248 | async def wait(self): |
| 249 | """Wait until notified. |
| 250 | |
| 251 | If the calling coroutine has not acquired the lock when this |
| 252 | method is called, a RuntimeError is raised. |
| 253 | |
| 254 | This method releases the underlying lock, and then blocks |
| 255 | until it is awakened by a notify() or notify_all() call for |
| 256 | the same condition variable in another coroutine. Once |
| 257 | awakened, it re-acquires the lock and returns True. |
| 258 | """ |
| 259 | if not self.locked(): |
| 260 | raise RuntimeError('cannot wait on un-acquired lock') |
| 261 | |
| 262 | self.release() |
| 263 | try: |
| 264 | fut = self._get_loop().create_future() |
| 265 | self._waiters.append(fut) |
| 266 | try: |
| 267 | await fut |
| 268 | return True |
| 269 | finally: |
| 270 | self._waiters.remove(fut) |
| 271 | |
| 272 | finally: |
| 273 | # Must reacquire lock even if wait is cancelled |
| 274 | cancelled = False |
| 275 | while True: |
| 276 | try: |
| 277 | await self.acquire() |
| 278 | break |
| 279 | except exceptions.CancelledError: |
| 280 | cancelled = True |
| 281 | |
| 282 | if cancelled: |
| 283 | raise exceptions.CancelledError |
| 284 | |
| 285 | async def wait_for(self, predicate): |
| 286 | """Wait until a predicate becomes true. |