-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-123271: Make builtin zip method safe under free-threading #123272
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
Changes from 12 commits
f9d44d1
2530fbe
1b592d2
bd9d9fb
d199600
54eb509
755a862
8c0fe40
1e8799f
bd3cc27
4fa48dd
0416f0b
4120b51
cc3e3cb
29b39d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import unittest | ||
from threading import Thread | ||
|
||
from test.support import threading_helper | ||
|
||
|
||
class ZipThreading(unittest.TestCase): | ||
@staticmethod | ||
def work(enum): | ||
while True: | ||
try: | ||
next(enum) | ||
except StopIteration: | ||
break | ||
|
||
@threading_helper.reap_threads | ||
@threading_helper.requires_working_threading() | ||
def test_threading(self): | ||
number_of_threads = 8 | ||
number_of_iterations = 40 | ||
n = 40_000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We run lots of unit tests in CI, so they individually need to be very fast. For the free-threaded tests, we should aim for <0.1 seconds on two cores (i.e., when run with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On my system (windows) the test is 0.07 seconds for the free-threading build. I will reduce the number of threads and iterations a bit so it is even faster. |
||
enum = zip(range(n), range(n)) | ||
for _ in range(number_of_iterations): | ||
worker_threads = [] | ||
for ii in range(number_of_threads): | ||
worker_threads.append( | ||
Thread( | ||
target=self.work, | ||
args=[ | ||
enum, | ||
], | ||
) | ||
) | ||
_ = [t.start() for t in worker_threads] | ||
_ = [t.join() for t in worker_threads] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The preferred style is to use |
||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Make concurrent iterations over the same :func:`zip` iterator safe under free-threading. |
Uh oh!
There was an error while loading. Please reload this page.