MCPcopy Index your code
hub / github.com/python/cpython / wait

Method wait

Lib/asyncio/locks.py:248–301  ·  view source on GitHub ↗

Wait until notified. If the calling task 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 same condition

(self)

Source from the content-addressed store, hash-verified

246 return f'<{res[1:-1]} [{extra}]>'
247
248 async def wait(self):
249 """Wait until notified.
250
251 If the calling task 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 task. Once
257 awakened, it re-acquires the lock and returns True.
258
259 This method may return spuriously,
260 which is why the caller should always
261 re-check the state and be prepared to wait() again.
262 """
263 if not self.locked():
264 raise RuntimeError('cannot wait on un-acquired lock')
265
266 fut = self._get_loop().create_future()
267 self.release()
268 try:
269 try:
270 self._waiters.append(fut)
271 try:
272 await fut
273 return True
274 finally:
275 self._waiters.remove(fut)
276
277 finally:
278 # Must re-acquire lock even if wait is cancelled.
279 # We only catch CancelledError here, since we don't want any
280 # other (fatal) errors with the future to cause us to spin.
281 err = None
282 while True:
283 try:
284 await self.acquire()
285 break
286 except exceptions.CancelledError as e:
287 err = e
288
289 if err is not None:
290 try:
291 raise err # Re-raise most recent exception instance.
292 finally:
293 err = None # Break reference cycles.
294 except BaseException:
295 # Any error raised out of here _may_ have occurred after this Task
296 # believed to have been successfully notified.
297 # Make sure to notify another Task instead. This may result
298 # in a "spurious wakeup", which is allowed as part of the
299 # Condition Variable protocol.
300 self._notify(1)
301 raise
302
303 async def wait_for(self, predicate):
304 """Wait until a predicate becomes true.

Callers 7

wait_forMethod · 0.95
test_wait_resultMethod · 0.95
test_wait_cancelMethod · 0.95
test_wait_unacquiredMethod · 0.95
wrong_loop_in_condMethod · 0.95
test_timeout_in_blockMethod · 0.95

Calls 8

_notifyMethod · 0.95
_get_loopMethod · 0.80
lockedMethod · 0.45
create_futureMethod · 0.45
releaseMethod · 0.45
appendMethod · 0.45
removeMethod · 0.45
acquireMethod · 0.45

Tested by 6

test_wait_resultMethod · 0.76
test_wait_cancelMethod · 0.76
test_wait_unacquiredMethod · 0.76
wrong_loop_in_condMethod · 0.76
test_timeout_in_blockMethod · 0.76