Skip to content

Retry for Synchronous Generator #64

Closed

Description

@heri16

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)

Activity

  1. RonnyPfannschmidt commented on Apr 23, 2017

    @RonnyPfannschmidt

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

  2. heri16 commented on Apr 25, 2017

    @heri16
    Author

    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.

  3. RonnyPfannschmidt commented on Apr 25, 2017

    @RonnyPfannschmidt

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

  4. untulis commented on Oct 20, 2022

    @untulis

    Would you accept a documentation PR to clarify this?

  5. jpmarques19 commented on Feb 1, 2025

    @jpmarques19

    I would

  6. added 2 commits that reference this issue on Feb 24, 2026
    897e175
    0be95b1
  7. added a commit that references this issue on Feb 24, 2026
    0a3ca8a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions