Comments (14)
Like the @on_predicate
lambda
from backoff.
Actual really dirty workaround:
class DoRetryException(BaseException):
"""
Used for backoff strategy
"""
pass
# end class DoRetryException
def should_backoff(e):
"""
Used for backoff strategy
"""
if e.error_code == 429 or "too many requests" in e.description or "retry later" in e.description:
raise DoRetryException()
# end if
# end def
class DocumentMessage():
# ...
# ...
@backoff.on_exception(backoff.expo, DoRetryException, max_tries=10, jitter=None)
def send(self, sender: PytgbotApiBot, receiver, reply_id)->PytgbotApiMessage:
try:
return sender.send_document(
receiver, self.file, caption=self.caption, reply_to_message_id=reply_id, reply_markup=self.reply_markup,
disable_notification=self.disable_notification
)
except TgApiServerException as e:
should_backoff(e) # checks if it should raise an DoRetryException
raise # else it just raises as usual
# end try
# end def send
from backoff.
I think this is basically the same as #8 ... I'm still thinking about the best way to accommodate it. Does the keyword arg solution I put there look like it would work for you?
from backoff.
The idea is to add a keyword arg which takes a function which tests the raised exception.
def is_fatal(e):
return e.error_number == 42
@backoff.on_exception(backoff.expo, SomeException,
giveup=is_fatal)
def foobar():
error_number = random.choice([42, 4458])
raise SomeException(error_number)
How does this look to you?
from backoff.
@luckydonald This PR adds a giveup
kwarg to on_exception: #13
from backoff.
Looks like the missing part :D
from backoff.
Should giveup(e)
be checked for raising exceptions itself, so another backoff round starts? Or should that just fail?
from backoff.
If there's an exception raised in your giveup function I believe that should be allowed to escape.
from backoff.
Yep, probably. Else errors there would be unnoticed.
from backoff.
When will there be a new pip
package? or did I miss that already?
from backoff.
Yes, this will be released and distributed on pypi as part of 1.3
from backoff.
backoff==1.3.1 is now released
from backoff.
Great!
from backoff.
#11 (comment)
In your code you say @backoff.on_exception(...):
where the :
is wrong.
Also could you please syntax highlight to your code (here and readme) as python by using ```python
?
from backoff.
Related Issues (20)
- Duplicate logging in some special cases HOT 1
- How do I use this?
- Obtain value returned by backoff_handler function after maximum tries is reached
- max_retries HOT 1
- max_time only applies _after_ first retry?
- Canonical way to handle error bursting
- Add exponential decay
- How to handle backoff on Facebook cursor? HOT 1
- Improve Typing and Error Handling in `on_exception`
- question about max_time
- Feature Request: add a way to use backoff in a context manager HOT 2
- feature request: toggle decorator on/off
- `backoff.on_predicate` does not work for `staticmethod`s
- Expose typing hints as they are part of the API
- Add support for globally disabling retries
- How to provide arguments to `on_backoff` function HOT 1
- Feature Request: support direct invocation with functools.partial
- Maintenance help? HOT 7
- README: `max_value` arg to `@backoff.on_predicate(backoff.fibo...)` -- if not obsolete, then maybe just confusing?
- Prevent error message in case of giveup using
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backoff.