|
|
@@ -44,15 +44,16 @@ def err(format, *args): |
|
|
|
fprintf(sys.stderr, format, *args) |
|
|
|
|
|
|
|
# Decorator that retries a function if it returns a specific value |
|
|
|
def retry_if_raised(exc, message = None): |
|
|
|
def retry_if_raised(exc, message = None, max_retries = 100): |
|
|
|
def f1(func): |
|
|
|
def f2(*args, **kwargs): |
|
|
|
while True: |
|
|
|
for n in range(max_retries): |
|
|
|
try: |
|
|
|
return func(*args, **kwargs) |
|
|
|
except exc as e: |
|
|
|
if message: |
|
|
|
log("%s\n\n", message) |
|
|
|
raise Exception("Max number of retries (%d) exceeded; giving up") |
|
|
|
return f2 |
|
|
|
return f1 |
|
|
|
|
|
|
|