From b966b7a2a93e4ecc1de494f7bae6defd273572e1 Mon Sep 17 00:00:00 2001 From: Val Brodsky Date: Thu, 5 Oct 2023 11:23:53 -0700 Subject: [PATCH 1/2] Replace backoff with google.api_core.retry --- labelbox/schema/annotation_import.py | 11 ++++------- labelbox/schema/bulk_import_request.py | 10 ++++------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/labelbox/schema/annotation_import.py b/labelbox/schema/annotation_import.py index 3e0fec607..02a4e0f20 100644 --- a/labelbox/schema/annotation_import.py +++ b/labelbox/schema/annotation_import.py @@ -5,7 +5,7 @@ import time from typing import Any, BinaryIO, Dict, List, Union, TYPE_CHECKING, cast -import backoff +from google.api_core import retry from labelbox import parser import requests from tqdm import tqdm # type: ignore @@ -109,12 +109,9 @@ def wait_until_done(self, pbar.update(100 - pbar.n) pbar.close() - @backoff.on_exception( - backoff.expo, - (labelbox.exceptions.ApiLimitError, labelbox.exceptions.TimeoutError, - labelbox.exceptions.NetworkError), - max_tries=10, - jitter=None) + @retry.Retry(predicate=retry.if_exception_type( + labelbox.exceptions.ApiLimitError, labelbox.exceptions.TimeoutError, + labelbox.exceptions.NetworkError)) def __backoff_refresh(self) -> None: self.refresh() diff --git a/labelbox/schema/bulk_import_request.py b/labelbox/schema/bulk_import_request.py index 3412da95c..9b4ff85ef 100644 --- a/labelbox/schema/bulk_import_request.py +++ b/labelbox/schema/bulk_import_request.py @@ -6,7 +6,7 @@ import logging from pathlib import Path import pydantic -import backoff +from google.api_core import retry from labelbox import parser import requests from pydantic import BaseModel, root_validator, validator @@ -197,11 +197,9 @@ def wait_until_done(self, sleep_time_seconds: int = 5) -> None: time.sleep(sleep_time_seconds) self.__exponential_backoff_refresh() - @backoff.on_exception( - backoff.expo, (lb_exceptions.ApiLimitError, lb_exceptions.TimeoutError, - lb_exceptions.NetworkError), - max_tries=10, - jitter=None) + @retry.Retry(predicate=retry.if_exception_type(lb_exceptions.ApiLimitError, + lb_exceptions.TimeoutError, + lb_exceptions.NetworkError)) def __exponential_backoff_refresh(self) -> None: self.refresh() From c6ae9b3104c8c36fef62ac15c5e2a32aeb02e16c Mon Sep 17 00:00:00 2001 From: Val Brodsky Date: Thu, 5 Oct 2023 11:26:15 -0700 Subject: [PATCH 2/2] Remove backoff from setup files --- .yapfignore | 4 +++- mypy.ini | 3 --- requirements.txt | 1 - setup.py | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.yapfignore b/.yapfignore index 81e3a94a2..1635ab39e 100644 --- a/.yapfignore +++ b/.yapfignore @@ -1 +1,3 @@ -pytest.ini +Makefile +*.txt +*.ini diff --git a/mypy.ini b/mypy.ini index 4e5254fa6..48135600e 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,8 +1,5 @@ [mypy] -[mypy-backoff.*] -ignore_missing_imports = True - [mypy-google.*] ignore_missing_imports = True diff --git a/requirements.txt b/requirements.txt index 6f6b55ebb..105abe1f4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -backoff==1.10.0 geojson google-api-core>=1.22.1 imagesize diff --git a/setup.py b/setup.py index e459b0f5e..a4407085a 100644 --- a/setup.py +++ b/setup.py @@ -20,8 +20,8 @@ url="https://labelbox.com", packages=setuptools.find_packages(), install_requires=[ - "backoff==1.10.0", "requests>=2.22.0", "google-api-core>=1.22.1", - "pydantic>=1.8,<2.0", "tqdm", "python-dateutil>=2.8.2,<2.9.0" + "requests>=2.22.0", "google-api-core>=1.22.1", "pydantic>=1.8,<2.0", + "tqdm", "python-dateutil>=2.8.2,<2.9.0" ], extras_require={ 'data': [