add comments from rdooley, add comment around stop behavior

This commit is contained in:
Ray Holder 2014-06-20 02:16:50 -05:00
parent e5fc513f5d
commit 8ca5b41bca
2 changed files with 8 additions and 1 deletions

View File

@ -16,3 +16,4 @@ Patches and Suggestions
- J Derek Wilson
- Alex Kuang
- Simon Dollé
- Rees Dooley

View File

@ -69,9 +69,12 @@ else:
# sys.maxint / 2, since Python 3.2 doesn't have a sys.maxint...
MAX_WAIT = 1073741823
def retry(*dargs, **dkw):
"""
TODO comment
Decorator function that instantiates the Retrying object
@param *dargs: positional arguments passed to Retrying object
@param **dkw: keyword arguments passed to the Retrying object
"""
# support both @retry and @retry() as valid syntax
if len(dargs) == 1 and callable(dargs[0]):
@ -238,6 +241,7 @@ class Retrying(object):
delay_since_first_attempt_ms = int(round(time.time() * 1000)) - start_time
if self.stop(attempt_number, delay_since_first_attempt_ms):
if not self._wrap_exception and attempt.has_exception:
# get() on an attempt with an exception should cause it to be raised, but raise just in case
raise attempt.get()
else:
raise RetryError(attempt)
@ -247,6 +251,7 @@ class Retrying(object):
attempt_number += 1
class Attempt(object):
"""
An Attempt encapsulates a call to a target function that may end as a
@ -279,6 +284,7 @@ class Attempt(object):
else:
return "Attempts: {0}, Value: {1}".format(self.attempt_number, self.value)
class RetryError(Exception):
"""
A RetryError encapsulates the last Attempt instance right before giving up.