mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-13 22:59:05 +00:00
core[patch]: use time.monotonic() instead time.time() in InMemoryRateLimiter
**Description:** The get time point method in the _consume() method of core.rate_limiters.InMemoryRateLimiter uses time.time(), which can be affected by system time backwards. Therefore, it is recommended to use the monotonically increasing monotonic() to obtain the time ```python with self._consume_lock: now = time.time() # time.time() -> time.monotonic() # initialize on first call to avoid a burst if self.last is None: self.last = now elapsed = now - self.last # when use time.time(), elapsed may be negative when system time backwards ```
This commit is contained in:
parent
bd6c31617e
commit
c3ced4c6ce
@ -181,7 +181,7 @@ class InMemoryRateLimiter(BaseRateLimiter):
|
|||||||
the caller should try again later.
|
the caller should try again later.
|
||||||
"""
|
"""
|
||||||
with self._consume_lock:
|
with self._consume_lock:
|
||||||
now = time.time()
|
now = time.monotonic()
|
||||||
|
|
||||||
# initialize on first call to avoid a burst
|
# initialize on first call to avoid a burst
|
||||||
if self.last is None:
|
if self.last is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user