Skip to content

GH-116738: document thread-safety of bisect #136555

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 7 commits into from
Jul 30, 2025
Merged
Changes from 1 commit
Commits
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
Use threading_helper.run_concurrently.
  • Loading branch information
nascheme committed Jul 23, 2025
commit 87a90f3c26d4be3ec4e22ef5884b911b3a015de1
24 changes: 1 addition & 23 deletions Lib/test/test_free_threading/test_bisect.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def insert(data):
insert_method(data, x)

data = list(range(OBJECT_COUNT))
self.run_concurrently(
threading_helper.run_concurrently(
worker_func=insert, args=(data,), nthreads=NTHREADS
)
if False:
Expand All @@ -42,28 +42,6 @@ def is_sorted_ascending(lst):
"""
return all(lst[i - 1] <= lst[i] for i in range(1, len(lst)))

def run_concurrently(self, worker_func, args, nthreads):
"""
Run the worker function concurrently in multiple threads.
"""
barrier = Barrier(nthreads)

def wrapper_func(*args):
# Wait for all threads to reach this point before proceeding.
barrier.wait()
worker_func(*args)

with threading_helper.catch_threading_exception() as cm:
workers = (
Thread(target=wrapper_func, args=args)
for _ in range(nthreads)
)
with threading_helper.start_threads(workers):
pass

# Worker threads should not raise any exceptions
self.assertIsNone(cm.exc_value)


@threading_helper.requires_working_threading()
class TestPyBisect(unittest.TestCase, TestBase):
Expand Down
Loading