Skip to content
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

Retry for Synchronous Generator #64

Open
heri16 opened this issue Apr 23, 2017 · 4 comments
Open

Retry for Synchronous Generator #64

heri16 opened this issue Apr 23, 2017 · 4 comments

Comments

@heri16
Copy link

heri16 commented Apr 23, 2017

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)
@RonnyPfannschmidt
Copy link

retry for generators breaks flow expectations, how would it correctly know what to do after say failure after the 5th item

@heri16
Copy link
Author

heri16 commented Apr 25, 2017

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.

@RonnyPfannschmidt
Copy link

and that would have unexpected cost and side-effects as well

@untulis
Copy link

untulis commented Oct 20, 2022

Would you accept a documentation PR to clarify this?

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

No branches or pull requests

3 participants