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

[BUG] Deadloop on LazyRepeater for non re-iterable. #1222

Open
chenjiasheng opened this issue Nov 25, 2023 · 2 comments
Open

[BUG] Deadloop on LazyRepeater for non re-iterable. #1222

chenjiasheng opened this issue Nov 25, 2023 · 2 comments

Comments

@chenjiasheng
Copy link

The LazyRepeater is intended for a re-iterable Iterable.
If the iterable is not re-iterable, for example, if it is a generator created by a generator expression or the yield keyword, then iterating on the LazyRepeater would hang indefinitely without yielding any real items when times is not specified, or it would yield fewer items than the user expected if times > 1.

Here is a simple reproduction of the issue:

it = (x for x in range(10))
repeated = LazyRepeater(iterable=it, times=None, preserve_id=True)
for x in repeated:
    print(x)
# Hangs after printing 10 numbers

My proposed solution:

  1. Add a "re-iterable" and "non-empty" restriction for the input iterable in the docstring.
  2. Whenever an epoch starts, if the very first yield statement raises a StopIteration error, then raise an Exception complaining about "not being non-empty" and "not being re-iterable" (for the second and later epochs only).
  3. Change the parameter name from 'iterator' to 'iterable' (however, this may cause backward compatibility issues).
@chenjiasheng
Copy link
Author

@oplatek @songmeixu @johnjosephmorgan @stachu86

@pzelasko
Copy link
Collaborator

I am OK with your proposed solution, could you make a PR?

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

2 participants