Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def failwhale_wrap(self, fn, *args, **kwargs):
- '''
- Catch the fail whale, and harpoon it! aka. Catch HTTP error 401 or 500,
- and retry 3 times, with a small delay in between before giving up and
- raising the last exception.
- @param[in] fn Function to call.
- @param[in] args Positional arguments.
- @param[in] kwargs Keyword arguments.
- @returns Function return code.
- '''
- for i in range(3):
- try:
- return fn(*args, **kwargs)
- except urllib2.HTTPError, e:
- if e.code not in (401, 500):
- break
- # Wait 100ms before trying again. Lame.
- time.sleep(0.1)
- raise e
Add Comment
Please, Sign In to add comment