Home / Function/ acquire() — langchain Function Reference

acquire() — langchain Function Reference

Architecture documentation for the acquire() function in rate_limiters.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  7eb4873b_0a65_ee74_d6ce_9f59f9def5b3["acquire()"]
  29cf4437_3b06_c93f_9779_9154d2ed9ff9["InMemoryRateLimiter"]
  7eb4873b_0a65_ee74_d6ce_9f59f9def5b3 -->|defined in| 29cf4437_3b06_c93f_9779_9154d2ed9ff9
  8b0c264d_4f93_5995_59df_1cee2a309abf["acquire()"]
  8b0c264d_4f93_5995_59df_1cee2a309abf -->|calls| 7eb4873b_0a65_ee74_d6ce_9f59f9def5b3
  e0964492_c52e_ec68_41ea_efa229196967["_consume()"]
  7eb4873b_0a65_ee74_d6ce_9f59f9def5b3 -->|calls| e0964492_c52e_ec68_41ea_efa229196967
  8b0c264d_4f93_5995_59df_1cee2a309abf["acquire()"]
  7eb4873b_0a65_ee74_d6ce_9f59f9def5b3 -->|calls| 8b0c264d_4f93_5995_59df_1cee2a309abf
  style 7eb4873b_0a65_ee74_d6ce_9f59f9def5b3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/rate_limiters.py lines 197–220

    def acquire(self, *, blocking: bool = True) -> bool:
        """Attempt to acquire a token from the rate limiter.

        This method blocks until the required tokens are available if `blocking`
        is set to `True`.

        If `blocking` is set to `False`, the method will immediately return the result
        of the attempt to acquire the tokens.

        Args:
            blocking: If `True`, the method will block until the tokens are available.
                If `False`, the method will return immediately with the result of
                the attempt.

        Returns:
            `True` if the tokens were successfully acquired, `False` otherwise.
        """
        if not blocking:
            return self._consume()

        while not self._consume():
            time.sleep(self.check_every_n_seconds)

        return True

Domain

Subdomains

Called By

Frequently Asked Questions

What does acquire() do?
acquire() is a function in the langchain codebase, defined in libs/core/langchain_core/rate_limiters.py.
Where is acquire() defined?
acquire() is defined in libs/core/langchain_core/rate_limiters.py at line 197.
What does acquire() call?
acquire() calls 2 function(s): _consume, acquire.
What calls acquire()?
acquire() is called by 1 function(s): acquire.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free