Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def retry(attempt, raise_on_fail=False):
- def decorator(func):
- def wrapper(*args, **kw):
- att = 0
- last_except = None
- while att < attempt:
- try:
- return func(*args, **kw)
- except Exception as e:
- att += 1
- last_except = e
- else:
- if raise_on_fail:
- raise Exception('Hit retry threshold, failed for {0}' % str(last_except))
- return None
- return wrapper
- return decorator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement