Created
December 26, 2018 08:50
-
-
Save surinkim/cb947ec1aa8099ece51eeb528674faae to your computer and use it in GitHub Desktop.
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
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