Skip to content

Commit 10d6017

Browse files
add back run_concurrently
1 parent 29da66d commit 10d6017

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Lib/test/test_free_threading/test_bisect.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
from test.support import import_helper, threading_helper
33
import random
4+
from threading import Thread, Barrier
45

56
py_bisect = import_helper.import_fresh_module('bisect', blocked=['_bisect'])
67
c_bisect = import_helper.import_fresh_module('bisect', fresh=['_bisect'])
@@ -18,7 +19,7 @@ def insert(data):
1819
insert_method(data, x)
1920

2021
data = list(range(OBJECT_COUNT))
21-
threading_helper.run_concurrently(
22+
self.run_concurrently(
2223
worker_func=insert, args=(data,), nthreads=NTHREADS
2324
)
2425
if False:
@@ -41,6 +42,28 @@ def is_sorted_ascending(lst):
4142
"""
4243
return all(lst[i - 1] <= lst[i] for i in range(1, len(lst)))
4344

45+
def run_concurrently(self, worker_func, args, nthreads):
46+
"""
47+
Run the worker function concurrently in multiple threads.
48+
"""
49+
barrier = Barrier(nthreads)
50+
51+
def wrapper_func(*args):
52+
# Wait for all threads to reach this point before proceeding.
53+
barrier.wait()
54+
worker_func(*args)
55+
56+
with threading_helper.catch_threading_exception() as cm:
57+
workers = (
58+
Thread(target=wrapper_func, args=args)
59+
for _ in range(nthreads)
60+
)
61+
with threading_helper.start_threads(workers):
62+
pass
63+
64+
# Worker threads should not raise any exceptions
65+
self.assertIsNone(cm.exc_value)
66+
4467

4568
@threading_helper.requires_working_threading()
4669
class TestPyBisect(unittest.TestCase, TestBase):

0 commit comments

Comments
 (0)