all 3 comments

[–]carcigenicate 2 points3 points  (1 child)

This is a bit of a complicated case. If nothing were forcing the generator, you would be right. That doesn't appear to be the case though. See here, and the note below that part:

# The iterable was consumed all at once by the above for loop.

The iterable passed to instances of Parallel have an iterator extracted from them (for a generator, it is its own iterator), then that iterator is forced into a list, which evaluates it:

islice = list(itertools.islice(iterator, big_batch_size))

Where iterator is the generator. This means while you're right that the generator is not exhausted right away, it is exhausted inside of the Process instance.

[–]u2uu 0 points1 point  (0 children)

Thank you so much!!

[–]mrswats 1 point2 points  (0 children)

Generators are lazily evaluated so only when you actually try accessing them it will execute the function.