Created
November 24, 2011 03:46
-
-
Save rcoh/1390585 to your computer and use it in GitHub Desktop.
fancy decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def retry_with_backoff(success_func, backoff_rate=2, checkback_time=1): | |
def wrap(f): | |
def new_function(*args, **kw): | |
try: | |
f(*args, **kw) | |
try_in(checkback_time, retry, [checkback_time, args, kw]) | |
finally: | |
pass | |
def retry(delay, args, kw): | |
if success_func(*args, **kw): | |
f(*args, **kw) | |
try_in(delay, retry, [delay*backoff_rate, args, kw]) | |
return new_function | |
return wrap | |
def try_in(t, f, args=[], kw={}): | |
Timer(t, f, args, kw).start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment