| OLD | NEW |
| 1 # Copyright (C) 2010 Google Inc. All rights reserved. | 1 # Copyright (C) 2010 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 def run(self, request): | 52 def run(self, request): |
| 53 self._total_sleep = 0 | 53 self._total_sleep = 0 |
| 54 self._backoff_seconds = self._initial_backoff_seconds | 54 self._backoff_seconds = self._initial_backoff_seconds |
| 55 while True: | 55 while True: |
| 56 try: | 56 try: |
| 57 return request() | 57 return request() |
| 58 except urllib2.HTTPError as e: | 58 except urllib2.HTTPError as e: |
| 59 if self._convert_404_to_None and e.code == 404: | 59 if self._convert_404_to_None and e.code == 404: |
| 60 return None | 60 return None |
| 61 self._check_for_timeout() | 61 self._check_for_timeout() |
| 62 _log.warn("Received HTTP status %s loading \"%s\". Retrying in
%s seconds..." % | 62 _log.warning("Received HTTP status %s loading \"%s\". Retrying
in %s seconds...", |
| 63 (e.code, e.filename, self._backoff_seconds)) | 63 e.code, e.filename, self._backoff_seconds) |
| 64 self._sleep() | 64 self._sleep() |
| 65 | 65 |
| 66 def _check_for_timeout(self): | 66 def _check_for_timeout(self): |
| 67 if self._total_sleep + self._backoff_seconds > self._timeout_seconds: | 67 if self._total_sleep + self._backoff_seconds > self._timeout_seconds: |
| 68 raise NetworkTimeout() | 68 raise NetworkTimeout() |
| 69 | 69 |
| 70 def _sleep(self): | 70 def _sleep(self): |
| 71 time.sleep(self._backoff_seconds) | 71 time.sleep(self._backoff_seconds) |
| 72 self._total_sleep += self._backoff_seconds | 72 self._total_sleep += self._backoff_seconds |
| 73 self._backoff_seconds *= self._grown_factor | 73 self._backoff_seconds *= self._grown_factor |
| OLD | NEW |