diff --git a/google/api_core/retry.py b/google/api_core/retry.py index ce496937b..961279a06 100644 --- a/google/api_core/retry.py +++ b/google/api_core/retry.py @@ -61,6 +61,7 @@ def check_if_exists(): import logging import random import time +import threading import requests.exceptions @@ -69,9 +70,12 @@ def check_if_exists(): from google.auth import exceptions as auth_exceptions _LOGGER = logging.getLogger(__name__) -_DEFAULT_INITIAL_DELAY = 1.0 # seconds -_DEFAULT_MAXIMUM_DELAY = 60.0 # seconds -_DEFAULT_DELAY_MULTIPLIER = 2.0 +# _DEFAULT_INITIAL_DELAY = 1.0 # seconds +# _DEFAULT_MAXIMUM_DELAY = 60.0 # seconds +# _DEFAULT_DELAY_MULTIPLIER = 2.0 +_DEFAULT_INITIAL_DELAY = 2.0 # seconds +_DEFAULT_MAXIMUM_DELAY = 2.0 # seconds +_DEFAULT_DELAY_MULTIPLIER = 1.0 _DEFAULT_DEADLINE = 60.0 * 2.0 # seconds @@ -143,7 +147,11 @@ def exponential_sleep_generator(initial, maximum, multiplier=_DEFAULT_DELAY_MULT while True: # Introduce jitter by yielding a delay that is uniformly distributed # to average out to the delay time. - yield min(random.uniform(0.0, delay * 2.0), maximum) + res = min(random.uniform(0.0, delay * 2.0), maximum) + _LOGGER.debug( + f"xxxxx: {threading.current_thread().name} exponential_sleep_generator initial: {initial}s, maximum: {maximum}s, multipier: {multiplier}s, res:{res}s" + ) + yield res delay = delay * multiplier @@ -187,7 +195,10 @@ def retry_target(target, predicate, sleep_generator, deadline, on_error=None): for sleep in sleep_generator: try: - return target() + _LOGGER.debug(f"xxxxx: {threading.current_thread().name} before target sleep: {sleep}") + res = target() + _LOGGER.debug(f"xxxxx: {threading.current_thread().name} res: {res}") + return res # pylint: disable=broad-except # This function explicitly must deal with broad exceptions. diff --git a/google/api_core/retry_async.py b/google/api_core/retry_async.py index 68a255973..ac930f9bc 100644 --- a/google/api_core/retry_async.py +++ b/google/api_core/retry_async.py @@ -142,7 +142,7 @@ async def retry_target(target, predicate, sleep_generator, deadline, on_error=No sleep = min(time_to_deadline, sleep) _LOGGER.debug( - "Retrying due to {}, sleeping {:.1f}s ...".format(last_exc, sleep) + "(Async) Retrying due to {}, sleeping {:.1f}s ...".format(last_exc, sleep) ) await asyncio.sleep(sleep)