diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-03 11:23:18 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-03 11:23:18 +0300 |
commit | 72425125ddc2243274edf6e48012987fb38a8f2a (patch) | |
tree | 4f054e6fd263674b7cd3f3558101c5733fe23951 /project/utils.py | |
parent | project.boost.download: add --no-retry parameter (diff) | |
download | cmake-common-72425125ddc2243274edf6e48012987fb38a8f2a.tar.gz cmake-common-72425125ddc2243274edf6e48012987fb38a8f2a.zip |
project.utils: fix the retry decorator
Diffstat (limited to 'project/utils.py')
-rw-r--r-- | project/utils.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/project/utils.py b/project/utils.py index f40767a..06fff27 100644 --- a/project/utils.py +++ b/project/utils.py @@ -91,17 +91,19 @@ def env(name): return os.environ[name] -def retry(exc_type, timeout=5, retries=3, backoff=2): +def retry(exc_type, timeout=5, tries=3, backoff=2): def wrapper(func): @functools.wraps(func) def func2(*args, **kwargs): current_timeout = timeout - for retry_n in range(retries): + current_try = 0 + while True: try: return func(*args, **kwargs) except exc_type as e: logging.exception(e) - if retry_n < retries: + current_try += 1 + if current_try < tries: logging.error('Retrying after %d seconds', current_timeout) time.sleep(current_timeout) current_timeout *= backoff |