add comments from rdooley, add comment around stop behavior
This commit is contained in:
parent
e5fc513f5d
commit
8ca5b41bca
|
@ -16,3 +16,4 @@ Patches and Suggestions
|
||||||
- J Derek Wilson
|
- J Derek Wilson
|
||||||
- Alex Kuang
|
- Alex Kuang
|
||||||
- Simon Dollé
|
- Simon Dollé
|
||||||
|
- Rees Dooley
|
|
@ -69,9 +69,12 @@ else:
|
||||||
# sys.maxint / 2, since Python 3.2 doesn't have a sys.maxint...
|
# sys.maxint / 2, since Python 3.2 doesn't have a sys.maxint...
|
||||||
MAX_WAIT = 1073741823
|
MAX_WAIT = 1073741823
|
||||||
|
|
||||||
|
|
||||||
def retry(*dargs, **dkw):
|
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
|
# support both @retry and @retry() as valid syntax
|
||||||
if len(dargs) == 1 and callable(dargs[0]):
|
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
|
delay_since_first_attempt_ms = int(round(time.time() * 1000)) - start_time
|
||||||
if self.stop(attempt_number, delay_since_first_attempt_ms):
|
if self.stop(attempt_number, delay_since_first_attempt_ms):
|
||||||
if not self._wrap_exception and attempt.has_exception:
|
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()
|
raise attempt.get()
|
||||||
else:
|
else:
|
||||||
raise RetryError(attempt)
|
raise RetryError(attempt)
|
||||||
|
@ -247,6 +251,7 @@ class Retrying(object):
|
||||||
|
|
||||||
attempt_number += 1
|
attempt_number += 1
|
||||||
|
|
||||||
|
|
||||||
class Attempt(object):
|
class Attempt(object):
|
||||||
"""
|
"""
|
||||||
An Attempt encapsulates a call to a target function that may end as a
|
An Attempt encapsulates a call to a target function that may end as a
|
||||||
|
@ -279,6 +284,7 @@ class Attempt(object):
|
||||||
else:
|
else:
|
||||||
return "Attempts: {0}, Value: {1}".format(self.attempt_number, self.value)
|
return "Attempts: {0}, Value: {1}".format(self.attempt_number, self.value)
|
||||||
|
|
||||||
|
|
||||||
class RetryError(Exception):
|
class RetryError(Exception):
|
||||||
"""
|
"""
|
||||||
A RetryError encapsulates the last Attempt instance right before giving up.
|
A RetryError encapsulates the last Attempt instance right before giving up.
|
||||||
|
|
Loading…
Reference in New Issue