def retries(timeout=30, intervals=1, clock=reactor):
"""Helper for retrying something, sleeping between attempts.
Returns a generator that yields ``(elapsed, remaining, wait)`` tuples,
giving times in seconds. The last item, `wait`, is the suggested amount of
time to sleep before trying again.
:param timeout: From now, how long to keep iterating, in seconds. This can
be specified as a number, or as an iterable. In the latter case, the
iterator is advanced each time an interval is needed. This allows for
back-off strategies.
:param intervals: The sleep between each iteration, in seconds, an an
iterable from which to obtain intervals.
:param clock: An optional `IReactorTime` provider. Defaults to the
installed reactor.
"""
start = clock.seconds()
end = start + timeout
if isinstance(intervals, Iterable):
intervals = iter(intervals)
else:
intervals = repeat(intervals)
return gen_retries(start, end, intervals, clock)
评论列表
文章目录