Skip to content

Instantly share code, notes, and snippets.

@rcoh
Created November 24, 2011 03:46
Show Gist options
  • Save rcoh/1390585 to your computer and use it in GitHub Desktop.
Save rcoh/1390585 to your computer and use it in GitHub Desktop.
fancy decorator
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