Skip to content

Instantly share code, notes, and snippets.

@surinkim
Created December 26, 2018 08:50
Show Gist options
  • Save surinkim/cb947ec1aa8099ece51eeb528674faae to your computer and use it in GitHub Desktop.
Save surinkim/cb947ec1aa8099ece51eeb528674faae to your computer and use it in GitHub Desktop.
import tenacity
import random
import time
start_time = time.time()
def do_something():
if random.randint(0, 0) == 0:
print("Failure")
raise RuntimeError
print("Success")
@tenacity.retry(
wait=tenacity.wait_exponential(multiplier=0.5, max=30, exp_base=2),
)
def do_something_and_retry():
global start_time
elapsed_time = time.time() - start_time
print(time.strftime("-- Elapsed time: %S seconds", time.gmtime(elapsed_time)))
start_time = time.time()
do_something()
do_something_and_retry()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment