Advertisement
Guest User

Untitled

a guest
May 29th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. def retry(attempt, raise_on_fail=False):
  2. def decorator(func):
  3. def wrapper(*args, **kw):
  4. att = 0
  5. last_except = None
  6. while att < attempt:
  7. try:
  8. return func(*args, **kw)
  9. except Exception as e:
  10. att += 1
  11. last_except = e
  12. else:
  13. if raise_on_fail:
  14. raise Exception('Hit retry threshold, failed for {0}' % str(last_except))
  15. return None
  16. return wrapper
  17. return decorator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement