diff options
author | 2017-07-10 22:28:50 +0200 | |
---|---|---|
committer | 2017-07-10 22:28:50 +0200 | |
commit | 064b7b3dbf4277b9c57add479a478386504fc0d2 (patch) | |
tree | 86ce96e6a71db9cfaccccbca1c1dee90ca9c2881 /common.py | |
parent | stabilization-candidates: update for git (diff) | |
download | arch-tools-064b7b3dbf4277b9c57add479a478386504fc0d2.tar.gz arch-tools-064b7b3dbf4277b9c57add479a478386504fc0d2.tar.bz2 arch-tools-064b7b3dbf4277b9c57add479a478386504fc0d2.zip |
Diffstat (limited to 'common.py')
-rw-r--r-- | common.py | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -1,10 +1,12 @@ # Copyright 2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +import functools import io import datetime import getpass import re +import time import portage @@ -17,6 +19,23 @@ def chunks(iterable, length): yield iterable[i:i + length] +def retry(ExceptionToCheck, tries=4, delay=3, backoff=2): + def deco_retry(f): + @functools.wraps(f) + def f_retry(*args, **kwargs): + mtries, mdelay = tries, delay + while mtries > 1: + try: + return f(*args, **kwargs) + except ExceptionToCheck: + time.sleep(mdelay) + mtries -= 1 + mdelay *= backoff + return f(*args, **kwargs) + return f_retry + return deco_retry + + # Snippet from http://bugs.python.org/issue9584 def expand_braces(orig): r = r'.*(\{.+?[^\\]\})' |