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

use itertools count for atomic increments #2280

Open
wants to merge 1 commit into
base: noetic-devel
Choose a base branch
from

Conversation

graingert
Copy link

No description provided.

@peci1
Copy link
Contributor

peci1 commented Apr 9, 2023

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...

@graingert
Copy link
Author

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

@peci1
Copy link
Contributor

peci1 commented Apr 9, 2023

Thanks for the explanation. And regarding the performance part? Is there some benefit?

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

Successfully merging this pull request may close these issues.

2 participants