Skip to content

Make Retrying object callable and store stats #7

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

underrun
Copy link

Because it is useful to do a one-off retry of a function.

Additionally, it is useful to be able to get stats from the retrying object - how many attempts were made, what time did the retry start.

I also altered the decorator a bit so that every call to the wrapped function is not creating a brand new Retrying object. Might not save a whole lot unless functions are called rapidly but its still less work to create it up front.

I also added a couple tests.

Because it is useful to do a one-off retry of a function.

Additionally, it is useful to be able to get stats from the retrying
object - how many attempts were made, what time did the retry start.
@underrun
Copy link
Author

any feedback? anything i can do to make this more attractive?

my thinking in usefulness would be something like wrapping other things that you might want to retry like:

from retrying import Retrying
import socket
ip = b'127.0.0.1'
port = 1234
retry_twice = Retrying(stop_max_attempt_number=3, wait_fixed=1)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
retry_twice(sock.sendto, b'this is some data to send', (ip, port))

Useful right?

@rholder
Copy link
Owner

rholder commented Jun 13, 2014

Sorry for the delay on vetting this. I haven't gotten around to digging in and doing some deeper regression/behavior testing with the constructor moving around to make sure everything stays scoped correctly. Exposing the stats are a great idea since they're already being tracked anyway. I plan to add this in to the next release. Thanks for the contribution, and I'll be sure to add you to the AUTHORS.rst.

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