Skip to content

Commit b61941b

Browse files
authored
chore(deps): upgrades pyrate-limiter (#1653)
1 parent 307f53f commit b61941b

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ dependencies = [
4848
"gql[requests,websockets] >= 3.5.0b5, < 4.0.0",
4949
"filelock >= 3.0.0, < 4.0.0",
5050
"pip-system-certs >= 4.0.0, < 5.0.0; platform_system=='Windows'",
51-
"pyrate-limiter >= 2, < 3",
51+
"pyrate-limiter >= 3, < 4",
5252
]
5353
urls = { homepage = "https://github.com/kili-technology/kili-python-sdk" }
5454

src/kili/core/graphql/graphql_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from gql.transport.requests import RequestsHTTPTransport
1515
from gql.transport.requests import log as gql_requests_logger
1616
from graphql import DocumentNode, print_schema
17-
from pyrate_limiter import Duration, Limiter, RequestRate
17+
from pyrate_limiter import Duration, Limiter, Rate
1818
from tenacity import (
1919
retry,
2020
retry_all,
@@ -39,7 +39,7 @@
3939
# they need to be shared between all instances of Kili client within the same process
4040

4141
# rate limiter to avoid sending too many queries to the backend
42-
_limiter = Limiter(RequestRate(MAX_CALLS_PER_MINUTE, Duration.MINUTE))
42+
_limiter = Limiter(Rate(MAX_CALLS_PER_MINUTE, Duration.MINUTE), max_delay=120 * 1000)
4343

4444
# mutex to avoid multiple threads sending queries to the backend at the same time
4545
_execute_lock = threading.Lock()
@@ -303,7 +303,8 @@ def _execute_with_retries(
303303
def _raw_execute(
304304
self, document: DocumentNode, variables: Optional[Dict], **kwargs
305305
) -> Dict[str, Any]:
306-
with _limiter.ratelimit("GraphQLClient.execute", delay=True), _execute_lock:
306+
_limiter.try_acquire("GraphQLClient.execute")
307+
with _execute_lock:
307308
return self._gql_client.execute(
308309
document=document,
309310
variable_values=variables,

tests/unit/test_graphql_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pytest_mock
1111
from gql import Client
1212
from gql.transport import exceptions
13-
from pyrate_limiter import Duration, Limiter, RequestRate
13+
from pyrate_limiter import Duration, Limiter, Rate
1414

1515
from kili.adapters.http_client import HttpClient
1616
from kili.core.constants import MAX_CALLS_PER_MINUTE
@@ -155,7 +155,7 @@ def test_rate_limiting(mocker: pytest_mock.MockerFixture):
155155
mocker.patch("kili.core.graphql.graphql_client.gql", side_effect=lambda x: x)
156156
mocker.patch(
157157
"kili.core.graphql.graphql_client._limiter",
158-
new=Limiter(RequestRate(MAX_CALLS_PER_MINUTE, Duration.SECOND * 5)),
158+
new=Limiter(Rate(MAX_CALLS_PER_MINUTE, Duration.SECOND * 5), max_delay=120 * 1000),
159159
)
160160
client = GraphQLClient(
161161
endpoint="",

0 commit comments

Comments
 (0)