-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
iter(range) shared by threads exceeds max range value #131199
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
Comments
Is this the same as the following issue? From https://docs.python.org/3/howto/free-threading-python.html#iterators:
I don't think we have plans to change that in 3.14. |
It doesn't seem to be a thread safety issue per se - the issue I'm surfacing is that the range max value is not respected. Calling next() on iterators returned from itertools.count() so far seems to be an atomic function that threads don't trip over, even in free-threaded code. The only real thread-safety issue I've found is when I intentionally introduce unsafe design requiring maintaining consistency between two state values Thanks for the link to the HOW_TO, I'll study that further. |
I've edited my code snippet to make it a little clearer where I'm having an issue. |
Yes, that's a thread safety issue. You're sharing an object between threads, but that object isn't implemented in a way that allows it to be safely shared between threads. The concurrent calls to its |
Bug report
Bug description:
I was experimenting with atomic updates to containers and iterators across threads, and wrote this code. The GIL-enabled version does not have an issue, but the free-threaded version overruns the range iterator.
(Tested using CPython 3.14a05)
With GIL enabled:
With free-threaded 3.14:
CPython versions tested on:
3.14
Operating systems tested on:
Windows
The text was updated successfully, but these errors were encountered: