Skip to content

list iterator __setstate__() differs for exhausted iterator GIL vs. non-GIL #129139

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

Open
tom-pytel opened this issue Jan 21, 2025 · 2 comments
Open
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading type-bug An unexpected behavior, bug, or error

Comments

@tom-pytel
Copy link
Contributor

Or is this too pedantic?

GIL enabled:

$ ./python
Python 3.14.0a4+ (heads/main:f3980af38b, Jan 21 2025, 11:34:12) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> it = iter([1]); list(it)
[1]
>>> it.__setstate__(0); list(it)
[]

GIL disabled:

$ ./python
Python 3.14.0a4+ experimental free-threading build (heads/main:f3980af38b, Jan 21 2025, 11:31:38) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> it = iter([1]); list(it)
[1]
>>> it.__setstate__(0); list(it)
[1]

v3.14, current main, its a one line fix.

@picnixz picnixz added type-bug An unexpected behavior, bug, or error interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading labels Jan 21, 2025
@eendebakpt
Copy link
Contributor

@Yhg1s Your changes in #128637 might result in a similar behavior change for tuple iterators as is described here for list iterators.

@Yhg1s
Copy link
Member

Yhg1s commented Jan 22, 2025

Yes, indeed. It's not difficult to fix, by the way, it just requires an extra check in the relevant __setstate__ methods. I'm not sure it's worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants