What am I doing wrong here. Trying to get chunks of a generator using islice, but seems to be running infinitely.
from itertools import islice
size = 2
def g():
for x in range(11):
print("generating: ", x)
yield x
while True:
chunk = islice(g(), size)
if not chunk:
break
print("at chunk")
for c in chunk:
print(c)
I am getting an output of, that seems to just loop forever and does not seem to increment:
at chunk
generating: 0
0
generating: 1
1
at chunk
generating: 0
0
generating: 1
1
at chunk
generating: 0
0
generating: 1
1
at chunk