Skip to content

Commit b8d8dfc

Browse files
committed
add unit test case
1 parent 3e24b32 commit b8d8dfc

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lib/test/test_free_threading/test_threading.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,40 @@ def mutate_thread():
2222
threading_helper.run_concurrently([repr_thread, mutate_thread])
2323

2424

25+
class TestShutdown(unittest.TestCase):
26+
def test_shutdown_race(self):
27+
import _thread
28+
import threading
29+
30+
ITERATIONS = 1_000
31+
STARTUP_THREADS = 4
32+
33+
def shutdown_worker():
34+
for _ in range(ITERATIONS):
35+
try:
36+
_thread._shutdown()
37+
except RuntimeError:
38+
pass
39+
40+
def startup_worker():
41+
handles = []
42+
for _ in range(ITERATIONS):
43+
handle = _thread.start_joinable_thread(
44+
lambda: None,
45+
daemon=False,
46+
)
47+
handles.append(handle)
48+
for handle in handles:
49+
handle.join()
50+
51+
workers = [
52+
threading.Thread(target=shutdown_worker, daemon=True),
53+
*[threading.Thread(
54+
target=startup_worker, daemon=True) for _ in range(STARTUP_THREADS)],
55+
]
56+
57+
with threading_helper.start_threads(workers):
58+
pass
59+
2560
if __name__ == "__main__":
2661
unittest.main()

0 commit comments

Comments
 (0)