retrying
retrying copied to clipboard
Make Retrying object callable and store stats
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.
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?
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
.