-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-126366: Make native generators thread safe #126371
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
Draft
ZeroIntensity
wants to merge
44
commits into
python:main
Choose a base branch
from
ZeroIntensity:list-init-thread-safety
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 14 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
f8b06ae
Lock the iterable for list.__init__()
ZeroIntensity cd6f573
Add blurb
ZeroIntensity 49fb9e5
Add a test.
ZeroIntensity ab087ce
Fix the test.
ZeroIntensity d332da1
Fix the test (again).
ZeroIntensity 61fa342
Fix doctest.
ZeroIntensity 6b6b8e6
Make generators thread safe.
ZeroIntensity 1b72842
Move test to test_generators.
ZeroIntensity 684ccaf
Update the blurb
ZeroIntensity 9edb265
Remove changes to list tests.
ZeroIntensity 3a1fe3a
Fix the test name.
ZeroIntensity 8e84dd4
Add a lock in the _SEND instruction
ZeroIntensity 517b7f8
Add a test in test_free_threading (by Ken)
ZeroIntensity 6276ae5
Fix failing build.
ZeroIntensity 570d80e
Revert "Lock the iterable for list.__init__()"
ZeroIntensity 29c90eb
Merge branch 'main' into list-init-thread-safety
ZeroIntensity 690f45b
Some small changes to the test.
ZeroIntensity 200ba8b
Update Lib/test/test_free_threading/test_generators.py
ZeroIntensity 51f2778
Lower iteration count.
ZeroIntensity 8dcba72
Merge branch 'list-init-thread-safety' of https://github.com/ZeroInte…
ZeroIntensity ebdc293
Merge branch 'main' of https://github.com/python/cpython into list-in…
ZeroIntensity 6447a82
Lock _PyGen_yf
ZeroIntensity efe9f87
Remove name change.
ZeroIntensity 55ea54d
Use a critical section for close()
ZeroIntensity 17b7acf
Fix races with gi_frame_state
ZeroIntensity ccc65c6
Rerun clinic.
ZeroIntensity 192b6a3
Put a critical section around bytecodes that access gi_frame_state
ZeroIntensity 2da4678
Add more to the test.
ZeroIntensity b34cde6
Add a comment.
ZeroIntensity 2d03a13
Prevent logs from getting spammed.
ZeroIntensity 80c3547
Update Objects/genobject.c
ZeroIntensity ee93193
Rerun clinic.
ZeroIntensity d6cc59a
Rename _gen_throw to gen_throw_lock_held
ZeroIntensity afbb669
Add helper for gen_close
ZeroIntensity 6e45597
Rename to gen_getframe_lock_held
ZeroIntensity 99105e7
Use argument clinic for some more things.
ZeroIntensity 560df73
Fix some coroutine thread safety.
ZeroIntensity 7cd787f
Fix inconsistency with naming.
ZeroIntensity 77a33bb
Add tests for coroutines.
ZeroIntensity 173ba3b
Add some locking assertions.
ZeroIntensity 770ce09
Don't try and re-lock the generator to clear it.
ZeroIntensity 81e90bf
Add tests for async generators.
ZeroIntensity 415f081
Revert "Don't try and re-lock the generator to clear it."
ZeroIntensity 5689653
Merge branch 'main' of https://github.com/python/cpython into list-in…
ZeroIntensity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import unittest | ||
import concurrent.futures | ||
|
||
from unittest import TestCase | ||
|
||
from test.support import threading_helper | ||
|
||
@threading_helper.requires_working_threading() | ||
class TestGen(TestCase): | ||
def test_generators_basic(self): | ||
def gen(): | ||
for _ in range(5000): | ||
yield | ||
|
||
|
||
it = gen() | ||
with concurrent.futures.ThreadPoolExecutor() as executor: | ||
for _ in range(5000): | ||
ZeroIntensity marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
executor.submit(lambda: next(it)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Core_and_Builtins/2024-11-03-15-07-15.gh-issue-126366.nd_LOu.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix possible data races when using :term:`generator iterator` objects concurrently. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.