-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-120608: Make reversed iterator work with free-threading #120971
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
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
57bc2dc
Make reversed iterator thread-safe
eendebakpt 7127a85
Add test for free-threading
eendebakpt 687a976
📜🤖 Added by blurb_it.
blurb-it[bot] a74a33c
Apply suggestions from code review
eendebakpt de1b3c6
make reversed_len thread safe
eendebakpt 3bef3fd
update news entry, make reversed_reduce safe
eendebakpt 220b414
update reversed_setstate for free-threading
eendebakpt 28aa548
Update Objects/enumobject.c
eendebakpt 2574051
Merge branch 'main' into reverse_ft_v2
eendebakpt e052ca4
simplify test
eendebakpt 8a7876a
Update Misc/NEWS.d/next/Core and Builtins/2024-06-24-20-08-55.gh-issu…
eendebakpt 081ba40
review comments: use for loop instead of comprehension
eendebakpt b2f2dd3
move test; skip free_after_iterating test on ft build
eendebakpt 8c6d136
Merge branch 'main' into reverse_ft_v2
eendebakpt 125645e
Merge branch 'main' into reverse_ft_v2
eendebakpt b90add3
Merge branch 'main' into reverse_ft_v2
eendebakpt 98f663c
Merge branch 'main' into reverse_ft_v2
eendebakpt 75a5fce
Merge branch 'main' into reverse_ft_v2
eendebakpt c7f6f92
lint
eendebakpt 568b6d4
Merge branch 'main' into reverse_ft_v2
eendebakpt a5524a6
Merge branch 'main' into reverse_ft_v2
eendebakpt a0c316b
improve test
eendebakpt fc80d56
use Barrier in the test
eendebakpt 4d2a7fc
Merge branch 'main' into reverse_ft_v2
eendebakpt b1071df
remove testing code
eendebakpt aa71804
review comments
eendebakpt 76931aa
rework
eendebakpt 2c5e7ef
add thread helper code
eendebakpt b36bd50
Update Lib/test/test_free_threading/test_reversed.py
kumaraditya303 01f31a7
use ctx manager
kumaraditya303 ff702ef
Merge branch 'main' into reverse_ft_v2
eendebakpt c4c1ea9
Remove trailing comma in .github/workflows/build.yml
ambv eb60c8f
Revert "Remove trailing comma in .github/workflows/build.yml"
ambv 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,39 @@ | ||
import unittest | ||
from threading import Barrier, Thread | ||
from test.support import threading_helper | ||
|
||
threading_helper.requires_working_threading(module=True) | ||
|
||
class TestReversed(unittest.TestCase): | ||
|
||
@threading_helper.reap_threads | ||
def test_reversed(self): | ||
# Iterating over the iterator with multiple threads should not | ||
# emit TSAN warnings | ||
number_of_iterations = 10 | ||
number_of_threads = 10 | ||
size = 1_000 | ||
|
||
barrier = Barrier(number_of_threads) | ||
def work(r): | ||
barrier.wait() | ||
while True: | ||
try: | ||
l = r.__length_hint__() | ||
next(r) | ||
except StopIteration: | ||
break | ||
assert 0 <= l <= size | ||
x = tuple(range(size)) | ||
|
||
for _ in range(number_of_iterations): | ||
r = reversed(x) | ||
worker_threads = [] | ||
for _ in range(number_of_threads): | ||
worker_threads.append(Thread(target=work, args=[r])) | ||
with threading_helper.start_threads(worker_threads): | ||
pass | ||
barrier.reset() | ||
|
||
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
4 changes: 4 additions & 0 deletions
4
Misc/NEWS.d/next/Core_and_Builtins/2024-06-24-20-08-55.gh-issue-120608.d75n8U.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,4 @@ | ||
Adapt :func:`reversed` for use in the free-theading build. | ||
The :func:`reversed` is still not thread-safe in the sense that concurrent | ||
iterations may see the same object, but they will not corrupt the interpreter | ||
state. |
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
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.