File tree Expand file tree Collapse file tree
Lib/test/test_free_threading Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import unittest
2- import threading
3- import _thread
42from test .support import threading_helper
53
64threading_helper .requires_working_threading (module = True )
97class TestRlock (unittest .TestCase ):
108 def test_repr_race (self ):
119 # gh-153292
10+ import _thread
1211 r = _thread .RLock ()
1312
1413 def repr_thread ():
@@ -23,42 +22,5 @@ def mutate_thread():
2322 threading_helper .run_concurrently ([repr_thread , mutate_thread ])
2423
2524
26- class TestShutdown (unittest .TestCase ):
27- def test_shutdown_race (self ):
28- ITERATIONS = 1_000
29- STARTUP_THREADS = 4
30-
31- def shutdown_worker ():
32- for _ in range (ITERATIONS ):
33- try :
34- _thread ._shutdown ()
35- except RuntimeError :
36- pass
37-
38- def startup_worker ():
39- for _ in range (ITERATIONS ):
40- handle = _thread .start_joinable_thread (
41- lambda : None ,
42- daemon = False ,
43- )
44- handle .join ()
45-
46- # The workers must be daemon threads so _thread._shutdown() ignores them
47- # and only scans the non-daemon handles created by startup_worker().
48- workers = [
49- threading .Thread (target = shutdown_worker , daemon = True ),
50- * [
51- threading .Thread (target = startup_worker , daemon = True )
52- for _ in range (STARTUP_THREADS )
53- ],
54- ]
55-
56- with threading_helper .catch_threading_exception () as cm :
57- with threading_helper .start_threads (workers ):
58- pass
59- if cm .exc_value is not None :
60- raise cm .exc_value
61-
62-
6325if __name__ == "__main__" :
6426 unittest .main ()
You can’t perform that action at this time.
0 commit comments