Comments (6)
I'd like to have more advanced logging or more generalized before/after callbacks.
It would be nice to:
- Access exception information (
exc_info
) in theafter
callback, if any. - Access all function arguments in
after
. Right now, only the function itsself is given.
from tenacity.
So I may be misunderstand the discussion here. Is the consensus that currently there exists no way to print the exception? Or is one known?
I looked through the code, and it seems to to not be possible. The before_sleep
callback is the only one that has access to the exception, via last_result
, but, notably, not exc_info
, which we'd need to actually print the traceback, only the exception instance itself..
from tenacity.
I guess you can more or less do everything here already, but I admit it might not be obvious.
The last thing I want is a gigantic patch for this use case, but if you can enhance the current code and function and just add generic stuff so that's possible to do, give it a try. :)
from tenacity.
The current state is sort of awkward for several reasons:
- The retry may not be configured to sleep so the name is unintuitive
- Assumes that an exception will be the cause of retries, but you can change this (e.g.
retry=retry_if_result(is_false_p)
). It doesn't crash, but it does print the nonsensical messageRetrying __main__.do_something_unreliable in 0 seconds as it raised None.
which misidentifies the reason for the retry. - The final exception before a stop isn't printed, but it is reraised so not really a deal-breaker, just awkward because the logging won't be consistent.
- The traceback isn't printed which is often really useful.
Instead, it would be nice to have an after_exception
hook that would log the exception and optionally the traceback and change the before_sleep
hook to simply state how long the sleep will be and not attempt to log the reason for the retry/sleep unless it can be fixed for the case where the retry reason is changed.
from tenacity.
Well the whole reason for the callbacks is that you can define your own behaviour. So if you find it awkward that the traceback is not printed, you can define a callback that would print the traceback (Point 4). Or define a callback that prints a more sensible message (Point 2). The included callbacks should only serve as examples.
Point 3 is not real an issue in my mind because the callback name is "before_sleep" and shouldn't be called on the final exception.
Point 1 is valid I think, but it is the best name I came up with :-)
from tenacity.
With #122, #124 and #126 landed all callbacks now have access to retry_state
which contains all information related to current retry call. I'm closing this.
from tenacity.
Related Issues (20)
- Differences in using `retry` with `AsyncMock` objects on Python 3.9 and Python 3.8 vs. newer Python HOT 1
- Any help needed for a new release? HOT 2
- attempt_number should be set to 0 HOT 1
- `tests/test_tornado.py::TestTornado - AttributeError: 'TestTornado' object has no attribute 'runTest'` w/ pytest-8.2.0 HOT 4
- Question: How to handle dynamically changing retry (think api throttling) HOT 1
- Readme formatting fell apart HOT 1
- Can't we define a retry method in the instance method?
- Disable when developing? HOT 2
- HelloGitHub Badge
- Add `__aexit__`and `__aenter__` to AttemptManager
- ImportError tenacity.asyncio HOT 15
- Bug introduced in tenacity 8.4.0: ModuleNotFoundError: No module named 'tenacity.asyncio' HOT 1
- 8.4.0 release is broken due to missing files HOT 11
- Coalesce multiple ORs into a single object
- Access all occurred exceptions in `RetryError` HOT 1
- Retry in recursive context is broken since 8.3.0 HOT 3
- 8.4.2 breaks ability to compose regular functions with `retry_base` HOT 3
- 8.4.2 breaks suggested way to overwrite tenacity behaviors on unit tests HOT 7
- 8.5.0 includes breaking changes on the statistics object HOT 6
- `wait_random_exponential` does not respect `min` HOT 1
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 tenacity.