Skip to content
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

Feature - Raise on Giveup #129

Merged
merged 9 commits into from
Jul 25, 2021
Merged

Conversation

mrname
Copy link
Contributor

@mrname mrname commented Jul 18, 2021

#118

Implement feature to optionally disable raising of exceptions on giveup.

Copy link
Member

@bgreen-litl bgreen-litl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. It looks good. I put a couple comments in line.

@@ -131,7 +131,7 @@ def retry_exception(target, wait_gen, exception,
async def retry(*args, **kwargs):

# update variables from outer function args
nonlocal max_tries, max_time
nonlocal max_tries, max_time, raise_on_giveup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to add raise_on_giveup to the nonlocal list here, because unlike max_tries and max_time, we are not reassigning the variable with the output of _maybe_call()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! Fixed

@@ -158,8 +158,10 @@ async def retry(*args, **kwargs):
elapsed >= max_time)

if giveup_result or max_tries_exceeded or max_time_exceeded:
await _call_handlers(on_giveup, **details)
raise
handler_result = await _call_handlers(on_giveup, **details)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works as is, because on_giveup is actually a list of handlers here. The user facing API accepts either a list or a single handler for on_giveup, but in this internal code path it has already been wrapped in a list if it was a single handler function. The question then is handler_result is the return value of which handler. See the implementation of _call_handlers() to see what I mean. I liked the thought of having the result value be that of the on_giveup handler, but I doubt think that works in practice. But let me know if you have any bright ideas.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, of course! I guess just a bare return or return None (and not promising to return any values from on_giveup handlers) makes the most sense maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to return explicit None

@bgreen-litl bgreen-litl merged commit bc33cbb into litl:master Jul 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants