Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/retry_decorator/decorators.py

Issue 12317103: Added gsutil to depot tools (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/retry_decorator/__init__.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 import time
2 from functools import wraps
3
4
5 def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logger=None):
6 """Retry calling the decorated function using an exponential backoff.
7
8 http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
9 original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry
10
11 :param ExceptionToCheck: the exception to check. may be a tuple of
12 exceptions to check
13 :type ExceptionToCheck: Exception or tuple
14 :param tries: number of times to try (not retry) before giving up
15 :type tries: int
16 :param delay: initial delay between retries in seconds
17 :type delay: int
18 :param backoff: backoff multiplier e.g. value of 2 will double the delay
19 each retry
20 :type backoff: int
21 :param logger: logger to use. If None, print
22 :type logger: logging.Logger instance
23 """
24 def deco_retry(f):
25
26 @wraps(f)
27 def f_retry(*args, **kwargs):
28 mtries, mdelay = tries, delay
29 while mtries > 1:
30 try:
31 return f(*args, **kwargs)
32 except ExceptionToCheck, e:
33 msg = "%s, Retrying in %d seconds..." % (str(e), mdelay)
34 if logger:
35 logger.warning(msg)
36 else:
37 print msg
38 time.sleep(mdelay)
39 mtries -= 1
40 mdelay *= backoff
41 return f(*args, **kwargs)
42
43 return f_retry # true decorator
44
45 return deco_retry
OLDNEW
« no previous file with comments | « third_party/retry_decorator/__init__.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698