Backoff code inside function
See original GitHub issueI am calling some functions of a lib i wanna backoff. Problem is, I cannot modify the lib.
import backoff from requests.exceptions import TimeoutError from somewhere import library
So I am looking for something like:
with backoff.on_exception(backoff.expo, TimeoutError, max_tries=8):
library.some_function(yada, blah, foo, bar)
# end if
or
while backoff.on_exception(backoff.expo, TimeoutError, max_tries=8):
library.some_function(yada, blah, foo, bar)
# end if
Not sure what is possible to do.
Edit (2017-04-27): Calling just one function can be solved like seen below
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
litl/backoff: Python library providing function decorators for ...
Backoff supports asynchronous execution in Python 3.5 and above. To use backoff in asynchronous code based on asyncio you simply need to apply...
Read more >Using the Library — Backoff-Utils 1.0.1 documentation
This library provides a simple one-line approach to using backoff strategies in your code. It provides a simple function ( backoff() ) and...
Read more >Exponential backoff algorithm in NodeJS | by Rajkumar Gaur
The code for the backoff function is wrapped inside a setTimeout that waits for a time of Math.pow(2, exponent) + Math.random() * 1000...
Read more >How to implement an exponential backoff retry strategy in ...
And second, make sure to put a limit to the number of retries so that the code eventually gives up and throws an...
Read more >Implementing exponential backoff | Cloud IoT Core ...
random_number_milliseconds is a random number of milliseconds less than or equal to 1000. This helps to avoid cases in which many clients are...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just realized: If it is a just a single function - even in a library - you could supply the decorator yourself: So as solution to just the problem written in the original posting (calling a single function) this should be sufficient:
@pquentin, to which of my suggestion did you refer?
@bgreen-litl, What about the
for
+with
? It also looks handy for normal code you don’t really wan’t to put in an extra function.So 2 lines would be still less than writing it yourself every time:
Now manually: