Open graingert opened 2 years ago
This is the style used in the stdlib see https://github.com/python/cpython/blob/3.11/Lib/asyncio/tasks.py#L32
The count object can't be garbage collected because the bound method keeps a reference to it
Thanks for the explanation. And regarding the performance part? Is there some benefit?
The provided code looks really suspicious. How is it guaranteed that the instance created by
count()
call is not garbage-collected? It would look more safe and descriptive to first store this instance and then use a lambda calling the iterator.Apart from that, does this PR solve a particular performance issue, or does it just modernize the code?
For other reviewers:
itertools.count()
is implemented in C++, so it locks GIL instead of a mutex. This might be actually faster. Or might not...