[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

itertools product(infinite iterator) hangs

I've been staring at this for a little while:

from itertools import product

class Naturals:
    def __iter__(self):
        i = 1
        while True:
            yield i
            i += 1

N = Naturals()
print(product(N))  # <--- hangs

When I run the above the call to product hangs but I can't see why. I
would expect that since I'm not iterating over the product it would
just call iter(N) but clearly not since iter(N) returns a generator
instantly where as product(N) hangs.

What am I missing?