MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / acquire

Method acquire

tools/python-3.11.9-amd64/Lib/asyncio/locks.py:364–398  ·  view source on GitHub ↗

Acquire a semaphore. If the internal counter is larger than zero on entry, decrement it by one and return True immediately. If it is zero on entry, block, waiting until some other coroutine has called release() to make it larger than 0, and then return

(self)

Source from the content-addressed store, hash-verified

362 any(not w.cancelled() for w in (self._waiters or ())))
363
364 async def acquire(self):
365 """Acquire a semaphore.
366
367 If the internal counter is larger than zero on entry,
368 decrement it by one and return True immediately. If it is
369 zero on entry, block, waiting until some other coroutine has
370 called release() to make it larger than 0, and then return
371 True.
372 """
373 if not self.locked():
374 self._value -= 1
375 return True
376
377 if self._waiters is None:
378 self._waiters = collections.deque()
379 fut = self._get_loop().create_future()
380 self._waiters.append(fut)
381
382 # Finally block should be called before the CancelledError
383 # handling as we don't want CancelledError to call
384 # _wake_up_first() and attempt to wake up itself.
385 try:
386 try:
387 await fut
388 finally:
389 self._waiters.remove(fut)
390 except exceptions.CancelledError:
391 if not fut.cancelled():
392 self._value += 1
393 self._wake_up_next()
394 raise
395
396 if self._value > 0:
397 self._wake_up_next()
398 return True
399
400 def release(self):
401 """Release a semaphore, incrementing the internal counter by one.

Callers

nothing calls this directly

Calls 7

lockedMethod · 0.95
_wake_up_nextMethod · 0.95
_get_loopMethod · 0.80
create_futureMethod · 0.45
appendMethod · 0.45
removeMethod · 0.45
cancelledMethod · 0.45

Tested by

no test coverage detected