Popular recipes tagged "retry" but not "loop"http://code.activestate.com/recipes/tags/retry-loop/2017-01-11T10:10:30-08:00ActiveState Code RecipesRetry Decorator in Python (Python) 2017-01-11T10:10:30-08:00Alfehttp://code.activestate.com/recipes/users/4182236/http://code.activestate.com/recipes/580745-retry-decorator-in-python/ <p style="color: grey"> Python recipe 580745 by <a href="/recipes/users/4182236/">Alfe</a> (<a href="/recipes/tags/aspect/">aspect</a>, <a href="/recipes/tags/except/">except</a>, <a href="/recipes/tags/exception/">exception</a>, <a href="/recipes/tags/retry/">retry</a>, <a href="/recipes/tags/try/">try</a>). </p> <p>This is a Python decorator which helps implementing an aspect oriented implementation of a <em>retrying</em> of certain steps which might fail sometimes. A typical example for this would be communication processes with the outside world, e. g. HTTP requests, allocation of some resource, etc. To use it, refactor the step in question into a (local) function and decorate this with the <code>retry</code> decorator. See examples in the discussion sector below.</p> A Python decorator that re-executes the function on condition (Python) 2012-07-24T09:51:48-07:00Chaobin Tang (唐超斌)http://code.activestate.com/recipes/users/4174076/http://code.activestate.com/recipes/578222-a-python-decorator-that-re-executes-the-function-o/ <p style="color: grey"> Python recipe 578222 by <a href="/recipes/users/4174076/">Chaobin Tang (唐超斌)</a> (<a href="/recipes/tags/closure/">closure</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/retry/">retry</a>). Revision 3. </p> <p>Sometimes we want a function to be able to be retried automatically, such as a function that does networking trying to write/read data through a pre-established connection. Instead of writing try/except everywhere, a decorator would save much code and provide a single copy of code to do all the work.</p>