Skip to content

Commit

Permalink
Merge pull request #197 from praw-dev/4291second
Browse files Browse the repository at this point in the history
Sleep for a full second when rate limit is expired with no remaining requests
  • Loading branch information
bboe authored Jan 26, 2025
2 parents dafd854 + d311d56 commit 1a95cd4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ prawcore follows `semantic versioning <https://semver.org/>`_.
Unreleased
----------

**Fixed**

- Increase half-second delay introduced in ``3.0.0`` to a full second delay.

3.0.0 (2025/01/25)
------------------

Expand Down
2 changes: 1 addition & 1 deletion prawcore/rate_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def update(self, response_headers: Mapping[str, str]):

if self.remaining <= 0:
self.next_request_timestamp_ns = now_ns + max(
NANOSECONDS / 2, seconds_to_reset * NANOSECONDS
NANOSECONDS, seconds_to_reset * NANOSECONDS
)
return

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_rate_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_update__delay_full_time_with_zero_remaining_and_no_sleep_time(
rate_limiter.update(self._headers(0, 100, 0))
assert rate_limiter.remaining == 0
assert rate_limiter.used == 100
assert rate_limiter.next_request_timestamp_ns == 37.5 * NANOSECONDS
assert rate_limiter.next_request_timestamp_ns == 38 * NANOSECONDS

def test_update__no_change_without_headers(self, rate_limiter):
prev = copy(rate_limiter)
Expand Down

0 comments on commit 1a95cd4

Please sign in to comment.