You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

237 lines
7.0 KiB

4 years ago
  1. Metadata-Version: 2.1
  2. Name: retrying
  3. Version: 1.3.3
  4. Summary: Retrying
  5. Home-page: https://github.com/rholder/retrying
  6. Author: Ray Holder
  7. Author-email: UNKNOWN
  8. License: Apache 2.0
  9. Keywords: decorator decorators retry retrying exception exponential backoff
  10. Platform: UNKNOWN
  11. Classifier: Intended Audience :: Developers
  12. Classifier: Natural Language :: English
  13. Classifier: License :: OSI Approved :: Apache Software License
  14. Classifier: Programming Language :: Python
  15. Classifier: Programming Language :: Python :: 2.6
  16. Classifier: Programming Language :: Python :: 2.7
  17. Classifier: Programming Language :: Python :: 3.2
  18. Classifier: Programming Language :: Python :: 3.3
  19. Classifier: Programming Language :: Python :: 3.4
  20. Classifier: Topic :: Internet
  21. Classifier: Topic :: Utilities
  22. Requires-Dist: six (>=1.7.0)
  23. Retrying
  24. =========================
  25. .. image:: https://travis-ci.org/rholder/retrying.png?branch=master
  26. :target: https://travis-ci.org/rholder/retrying
  27. .. image:: https://badge.fury.io/py/retrying.png
  28. :target: https://pypi.python.org/pypi/retrying
  29. .. image:: https://pypip.in/d/retrying/badge.png
  30. :target: https://pypi.python.org/pypi/retrying
  31. Retrying is an Apache 2.0 licensed general-purpose retrying library, written in
  32. Python, to simplify the task of adding retry behavior to just about anything.
  33. The simplest use case is retrying a flaky function whenever an Exception occurs
  34. until a value is returned.
  35. .. code-block:: python
  36. import random
  37. from retrying import retry
  38. @retry
  39. def do_something_unreliable():
  40. if random.randint(0, 10) > 1:
  41. raise IOError("Broken sauce, everything is hosed!!!111one")
  42. else:
  43. return "Awesome sauce!"
  44. print do_something_unreliable()
  45. Features
  46. --------
  47. - Generic Decorator API
  48. - Specify stop condition (i.e. limit by number of attempts)
  49. - Specify wait condition (i.e. exponential backoff sleeping between attempts)
  50. - Customize retrying on Exceptions
  51. - Customize retrying on expected returned result
  52. Installation
  53. ------------
  54. To install retrying, simply:
  55. .. code-block:: bash
  56. $ pip install retrying
  57. Or, if you absolutely must:
  58. .. code-block:: bash
  59. $ easy_install retrying
  60. But, you might regret that later.
  61. Examples
  62. ----------
  63. As you saw above, the default behavior is to retry forever without waiting.
  64. .. code-block:: python
  65. @retry
  66. def never_give_up_never_surrender():
  67. print "Retry forever ignoring Exceptions, don't wait between retries"
  68. Let's be a little less persistent and set some boundaries, such as the number of attempts before giving up.
  69. .. code-block:: python
  70. @retry(stop_max_attempt_number=7)
  71. def stop_after_7_attempts():
  72. print "Stopping after 7 attempts"
  73. We don't have all day, so let's set a boundary for how long we should be retrying stuff.
  74. .. code-block:: python
  75. @retry(stop_max_delay=10000)
  76. def stop_after_10_s():
  77. print "Stopping after 10 seconds"
  78. Most things don't like to be polled as fast as possible, so let's just wait 2 seconds between retries.
  79. .. code-block:: python
  80. @retry(wait_fixed=2000)
  81. def wait_2_s():
  82. print "Wait 2 second between retries"
  83. Some things perform best with a bit of randomness injected.
  84. .. code-block:: python
  85. @retry(wait_random_min=1000, wait_random_max=2000)
  86. def wait_random_1_to_2_s():
  87. print "Randomly wait 1 to 2 seconds between retries"
  88. Then again, it's hard to beat exponential backoff when retrying distributed services and other remote endpoints.
  89. .. code-block:: python
  90. @retry(wait_exponential_multiplier=1000, wait_exponential_max=10000)
  91. def wait_exponential_1000():
  92. print "Wait 2^x * 1000 milliseconds between each retry, up to 10 seconds, then 10 seconds afterwards"
  93. We have a few options for dealing with retries that raise specific or general exceptions, as in the cases here.
  94. .. code-block:: python
  95. def retry_if_io_error(exception):
  96. """Return True if we should retry (in this case when it's an IOError), False otherwise"""
  97. return isinstance(exception, IOError)
  98. @retry(retry_on_exception=retry_if_io_error)
  99. def might_io_error():
  100. print "Retry forever with no wait if an IOError occurs, raise any other errors"
  101. @retry(retry_on_exception=retry_if_io_error, wrap_exception=True)
  102. def only_raise_retry_error_when_not_io_error():
  103. print "Retry forever with no wait if an IOError occurs, raise any other errors wrapped in RetryError"
  104. We can also use the result of the function to alter the behavior of retrying.
  105. .. code-block:: python
  106. def retry_if_result_none(result):
  107. """Return True if we should retry (in this case when result is None), False otherwise"""
  108. return result is None
  109. @retry(retry_on_result=retry_if_result_none)
  110. def might_return_none():
  111. print "Retry forever ignoring Exceptions with no wait if return value is None"
  112. Any combination of stop, wait, etc. is also supported to give you the freedom to mix and match.
  113. Contribute
  114. ----------
  115. #. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
  116. #. Fork `the repository`_ on GitHub to start making your changes to the **master** branch (or branch off of it).
  117. #. Write a test which shows that the bug was fixed or that the feature works as expected.
  118. #. Send a pull request and bug the maintainer until it gets merged and published. :) Make sure to add yourself to AUTHORS_.
  119. .. _`the repository`: http://github.com/rholder/retrying
  120. .. _AUTHORS: https://github.com/rholder/retrying/blob/master/AUTHORS.rst
  121. .. :changelog:
  122. History
  123. -------
  124. 1.3.3 (2014-12-14)
  125. ++++++++++++++++++
  126. - Add minimum six version of 1.7.0 since anything less will break things
  127. 1.3.2 (2014-11-09)
  128. ++++++++++++++++++
  129. - Ensure we wrap the decorated functions to prevent information loss
  130. - Allow a jitter value to be passed in
  131. 1.3.1 (2014-09-30)
  132. ++++++++++++++++++
  133. - Add requirements.txt to MANIFEST.in to fix pip installs
  134. 1.3.0 (2014-09-30)
  135. ++++++++++++++++++
  136. - Add upstream six dependency, remove embedded six functionality
  137. 1.2.3 (2014-08-25)
  138. ++++++++++++++++++
  139. - Add support for custom wait and stop functions
  140. 1.2.2 (2014-06-20)
  141. ++++++++++++++++++
  142. - Bug fix to not raise a RetryError on failure when exceptions aren't being wrapped
  143. 1.2.1 (2014-05-05)
  144. ++++++++++++++++++
  145. - Bug fix for explicitly passing in a wait type
  146. 1.2.0 (2014-05-04)
  147. ++++++++++++++++++
  148. - Remove the need for explicit specification of stop/wait types when they can be inferred
  149. - Add a little checking for exception propagation
  150. 1.1.0 (2014-03-31)
  151. ++++++++++++++++++
  152. - Added proper exception propagation through reraising with Python 2.6, 2.7, and 3.2 compatibility
  153. - Update test suite for behavior changes
  154. 1.0.1 (2013-03-20)
  155. ++++++++++++++++++
  156. - Fixed a bug where classes not extending from the Python exception hierarchy could slip through
  157. - Update test suite for custom Python exceptions
  158. 1.0.0 (2013-01-21)
  159. ++++++++++++++++++
  160. - First stable, tested version now exists
  161. - Apache 2.0 license applied
  162. - Sanitizing some setup.py and test suite running
  163. - Added Travis CI support