MCPcopy Index your code
hub / github.com/RustPython/RustPython / acquire

Method acquire

Lib/threading.py:482–525  ·  view source on GitHub ↗

Acquire a semaphore, decrementing the internal counter by one. When invoked without arguments: if the internal counter is larger than zero on entry, decrement it by one and return immediately. If it is zero on entry, block, waiting until some other thread has called release(

(self, blocking=True, timeout=None)

Source from the content-addressed store, hash-verified

480 f" value={self._value}>")
481
482 def acquire(self, blocking=True, timeout=None):
483 """Acquire a semaphore, decrementing the internal counter by one.
484
485 When invoked without arguments: if the internal counter is larger than
486 zero on entry, decrement it by one and return immediately. If it is zero
487 on entry, block, waiting until some other thread has called release() to
488 make it larger than zero. This is done with proper interlocking so that
489 if multiple acquire() calls are blocked, release() will wake exactly one
490 of them up. The implementation may pick one at random, so the order in
491 which blocked threads are awakened should not be relied on. There is no
492 return value in this case.
493
494 When invoked with blocking set to true, do the same thing as when called
495 without arguments, and return true.
496
497 When invoked with blocking set to false, do not block. If a call without
498 an argument would block, return false immediately; otherwise, do the
499 same thing as when called without arguments, and return true.
500
501 When invoked with a timeout other than None, it will block for at
502 most timeout seconds. If acquire does not complete successfully in
503 that interval, return false. Return true otherwise.
504
505 """
506 if not blocking and timeout is not None:
507 raise ValueError("can't specify timeout for non-blocking acquire")
508 rc = False
509 endtime = None
510 with self._cond:
511 while self._value == 0:
512 if not blocking:
513 break
514 if timeout is not None:
515 if endtime is None:
516 endtime = _time() + timeout
517 else:
518 timeout = endtime - _time()
519 if timeout <= 0:
520 break
521 self._cond.wait(timeout)
522 else:
523 self._value -= 1
524 rc = True
525 return rc
526
527 __enter__ = acquire
528

Callers

nothing calls this directly

Calls 2

_timeFunction · 0.90
waitMethod · 0.45

Tested by

no test coverage detected