comparison python/example/retry.py @ 758:88f19ebb43ea

add example retry function
author Jeff Hammel <k0scist@gmail.com>
date Mon, 31 Aug 2015 08:54:57 -0700
parents
children
comparison
equal deleted inserted replaced
757:af7b427b3b83 758:88f19ebb43ea
1 def retry(f, retries=5, args=(), kw=None, exceptions=()):
2
3 kw = kw or {}
4 for index in range(retries):
5 try:
6 return f(*args, **kw)
7 except Exception as e:
8 if isinstance(e, exceptions):
9 print ("something bad happen")
10 else:
11 raise
12 raise RetryTimeout("Tries a bunch of times :(")