-
-
Notifications
You must be signed in to change notification settings - Fork 281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a context manager #48
Comments
Yes, I think having a context manager would be an interesting feature. :) |
So there's actually no interesting thing we can do with the Basically your example turns down to be just: f = tenacity.Retrying(stop=stop_after_attempt(max_attempt)
f.call(foo, 3) I've added f = tenacity.Retrying(stop=stop_after_attempt(max_attempt)
f(foo, 3) |
This is not a with statement, but it's as easy as shown in #48.
+1 I am still novice in Python, so it seem's the |
What about something like this:
With something like this:
|
@proppy sounds like a good idea. It's not much different than doing |
I would prefer the context manager to be more Pythonic:
OR
|
@heri16 There's no need for a context manager in this case… you can just do |
See Issue jd#48 Example: ```python with RetryingContext(open) as open: with open('filename.txt', 'r') as file: ... ```
Alternative implementation. See Issue jd#48 Example: ```python with RetryingContext(open) as open: with open('filename.txt', 'r') as file: ... ```
See Issue jd#48 Example: ```python async with AsyncRetryingContext(open)('filename.txt', 'r') as file: ... ```
Alternative implementation See Issue jd#48 Example: ```python with AsyncRetryingContext(open) as open: async with open('filename.txt', 'r') as file: ... ```
@jd I see what you mean. |
I took a look at your idea @proppy but unfortunately, there's no way to re-call the function in So while, it'd be a nice addition, until Python transforms itself more into a Lisp and adds some macro support or something like that, this seems impossible to implement. |
@jd Sorry for the lack of update. I was thinking retry wouldn't really need to know about the code being retried, if it provide something that yields "Attempt context-managers". Something like this:
Each
What do you think? |
That looks like cutting the workflow in piece but I can see some value. If you can make it, go ahead. |
@jd does it looks like a big refactoring of tenacity code ? Do you have some insight to give us so to contribute ? |
I don't think it's a lot of refactoring nowadays. You could probably add an Then |
maybe helpful, maybe not, but i implemented the contexts in the ruby |
@apurvis Python does not have big-lambda like Ruby's block. So the context is quite more complex in python, we need to combine a generator and a context manager. |
We have this now. |
I like the idea from https://github.com/bhearsum/redo to have
retrying
contextmanager:Do you think is may be included in the
tenacity
? I have no clue if it works withasync
andfutures
.The text was updated successfully, but these errors were encountered: