-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-124397: Add threading.iter_locked #133908
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
base: main
Are you sure you want to change the base?
Conversation
@serhiy-storchaka, what was the rationale behind putting this in the |
|
||
The ``iter_locked`` makes non-atomic iterators atomic:: | ||
|
||
class non_atomic_iterator: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure non_atomic_iterator
is a good example of something that exists in the wild, because it's not thread-safe on GIL-ful builds either. The thread can arbitrarily switch during execution of Python code, so this would need a lock anyway if concurrent iteration were a use case. For free-threading, __next__
itself should have its own locking to prevent races. How was this design reached?
|
|
Continuation of #133272
Name was discussed in https://discuss.python.org/t/name-for-new-itertools-object-to-make-iterators-thread-safe/90394
📚 Documentation preview 📚: https://cpython-previews--133908.org.readthedocs.build/