8000 gh-120608: Make reversed iterator work with free-threading by eendebakpt · Pull Request #120971 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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 33 commits into from
Mar 12, 2025
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
57bc2dc
Make reversed iterator thread-safe
eendebakpt Jun 24, 2024
7127a85
Add test for free-threading
eendebakpt Jun 24, 2024
687a976
📜🤖 Added by blurb_it.
blurb-it[bot] Jun 24, 2024
a74a33c
Apply suggestions from code review
eendebakpt Jun 25, 2024
de1b3c6
make reversed_len thread safe
eendebakpt Jun 25, 2024
3bef3fd
update news entry, make reversed_reduce safe
eendebakpt Jun 25, 2024
220b414
update reversed_setstate for free-threading
eendebakpt Jun 26, 2024
28aa548
Update Objects/enumobject.c
eendebakpt Jun 26, 2024
2574051
Merge branch 'main' into reverse_ft_v2
eendebakpt Jun 26, 2024
e052ca4
simplify test
eendebakpt Jun 26, 2024
8a7876a
Update Misc/NEWS.d/next/Core and Builtins/2024-06-24-20-08-55.gh-issu…
eendebakpt Jul 8, 2024
081ba40
review comments: use for loop instead of comprehension
eendebakpt Jul 8, 2024
b2f2dd3
move test; skip free_after_iterating test on ft build
eendebakpt Jul 8, 2024
8c6d136
Merge branch 'main' into reverse_ft_v2
eendebakpt Jul 8, 2024
125645e
Merge branch 'main' into reverse_ft_v2
eendebakpt Aug 7, 2024
b90add3
Merge branch 'main' into reverse_ft_v2
eendebakpt Aug 23, 2024
98f663c
Merge branch 'main' into reverse_ft_v2
eendebakpt Oct 15, 2024
75a5fce
Merge branch 'main' into reverse_ft_v2
eendebakpt Nov 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for free-threading
  • Loading branch information
eendebakpt committed Jun 24, 2024
commit 7127a856b5f88e1773e89ee09079f9a4c9091f14
34 changes: 34 additions & 0 deletions Lib/test/test_reversed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unittest
from threading import Thread
from test.support import threading_helper


@threading_helper.reap_threads
@threading_helper.requires_working_threading()
def test_reversed_threading(self):
# Test that when reading out with multiple treads no identical elemenents are returned
def work(r, output):
while True:
try:
value = next(r)
except StopIteration:
break
else:
output.append(value)

number_of_threads = 10
x = tuple(range(4_000))
r = reversed(x)
worker_threads = []
output = []
for ii in range(number_of_threads):
worker_threads.append(Thread(target=work, args=[r, output]))
_ = [t.start() for t in worker_threads]
_ = [t.join() for t in worker_threads]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the preference I've heard from other core developers is to use for loops instead of using list comprehensions for their side-effects.


if sorted(output) != x:
raise ValueError('reversed returned value from sequence twice')


if __name__ == "__main__":
unittest.main()
Loading
0