Skip to content

Instantly share code, notes, and snippets.

@dsaiztc
Last active July 12, 2017 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsaiztc/d438ae50c71cd504fa6a68503ff6178d to your computer and use it in GitHub Desktop.
Save dsaiztc/d438ae50c71cd504fa6a68503ff6178d to your computer and use it in GitHub Desktop.
Exponential backoff.
from time import sleep
def try():
success = False
retries = 0
max_retries = N
while not success:
# Execute task, success = True if successful
if retries == max_retries:
raise Error
retries += 1
sleep(2.**retries * 0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment