def gen_retries(start, end, intervals, clock=reactor):
"""Helper for retrying something, sleeping between attempts.
Yields ``(elapsed, remaining, wait)`` tuples, giving times in seconds. The
last item, `wait`, is the suggested amount of time to sleep before trying
again.
This function works in concert with `retries`. It's split out so that
`retries` can capture the correct start time rather than the time at which
it is first iterated.
:param start: The start time, in seconds, of this generator. This must be
congruent with the `IReactorTime` argument passed to this generator.
:param end: The desired end time, in seconds, of this generator. This must
be congruent with the `IReactorTime` argument passed to this
generator.
:param intervals: A iterable of intervals, each in seconds, which should
be used as hints for the `wait` value that's generated.
:param clock: An optional `IReactorTime` provider. Defaults to the
installed reactor.
"""
for interval in intervals:
now = clock.seconds()
if now < end:
wait = min(interval, end - now)
yield now - start, end - now, wait
else:
yield now - start, end - now, 0
break
评论列表
文章目录