# HG changeset patch # User Jeff Hammel # Date 1441036497 25200 # Node ID 88f19ebb43eacef422d6002dfb550e71a8e51832 # Parent af7b427b3b83294080a613770857fb96de7373ed add example retry function diff -r af7b427b3b83 -r 88f19ebb43ea python/example/retry.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/example/retry.py Mon Aug 31 08:54:57 2015 -0700 @@ -0,0 +1,12 @@ +def retry(f, retries=5, args=(), kw=None, exceptions=()): + + kw = kw or {} + for index in range(retries): + try: + return f(*args, **kw) + except Exception as e: + if isinstance(e, exceptions): + print ("something bad happen") + else: + raise + raise RetryTimeout("Tries a bunch of times :(") \ No newline at end of file