MCPcopy
hub / github.com/python-trio/trio / acquire_on_behalf_of_nowait

Method acquire_on_behalf_of_nowait

src/trio/_sync.py:319–344  ·  view source on GitHub ↗

Borrow a token from the sack on behalf of ``borrower``, without blocking. Args: borrower: A :class:`trio.lowlevel.Task` or arbitrary opaque object used to record who is borrowing this token. This is used by :func:`trio.to_thread.run_sync` to allow

(self, borrower: Task | object)

Source from the content-addressed store, hash-verified

317
318 @enable_ki_protection
319 def acquire_on_behalf_of_nowait(self, borrower: Task | object) -> None:
320 """Borrow a token from the sack on behalf of ``borrower``, without
321 blocking.
322
323 Args:
324 borrower: A :class:`trio.lowlevel.Task` or arbitrary opaque object
325 used to record who is borrowing this token. This is used by
326 :func:`trio.to_thread.run_sync` to allow threads to "hold
327 tokens", with the intention in the future of using it to `allow
328 deadlock detection and other useful things
329 <https://github.com/python-trio/trio/issues/182>`__
330
331 Raises:
332 WouldBlock: if no tokens are available.
333 RuntimeError: if ``borrower`` already holds one of this sack&#x27;s
334 tokens.
335
336 """
337 if borrower in self._borrowers:
338 raise RuntimeError(
339 "this borrower is already holding one of this CapacityLimiter's tokens",
340 )
341 if len(self._borrowers) < self._total_tokens and not self._lot:
342 self._borrowers.add(borrower)
343 else:
344 raise trio.WouldBlock
345
346 @enable_ki_protection
347 async def acquire(self) -> None:

Callers 3

acquire_nowaitMethod · 0.95
acquire_on_behalf_ofMethod · 0.95
test_CapacityLimiterFunction · 0.95

Calls 1

addMethod · 0.80

Tested by 1

test_CapacityLimiterFunction · 0.76