tenacity
tenacity copied to clipboard
Retry for Synchronous Generator
Could we support retry for Synchronous Generator?
import random
from tenacity import retry
@retry
def ticker(to):
"""Yield numbers from 0 to `to`."""
for i in range(to):
if random.randint(0, 10) > 1:
raise IOError("Broken sauce, everything is hosed!!!111one")
else:
yield i
for i in ticker(10):
print(i)
retry for generators breaks flow expectations, how would it correctly know what to do after say failure after the 5th item
Good point. Generators uses exceptions internally. we would need to clone the generator first (itertools.tee) and then catch anything other than the StopIteration or GeneratorExit exception.
and that would have unexpected cost and side-effects as well
Would you accept a documentation PR to clarify this?