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 22
33import threading
44from threading import Thread
5+ import time
56from unittest import TestCase
67import gc
78
@@ -94,6 +95,27 @@ def evil():
9495 thread .start ()
9596 thread .join ()
9697
98+ def test_gc_callbacks_race_with_mutation (self ):
99+ def collect ():
100+ b .wait ()
101+ while not stop .is_set ():
102+ gc .collect ()
103+
104+ def mutate ():
105+ b .wait ()
106+ while not stop .is_set ():
107+ gc .callbacks [:] = [lambda * _ : _ for _ in range (16 )]
108+ time .sleep (0 )
109+ gc .callbacks .clear ()
110+
111+ threads = [threading .Thread (target = f ) for f in (collect , mutate ) * 4 ]
112+ b = threading .Barrier (len (threads ) + 1 )
113+ stop = threading .Event ()
114+
115+ with threading_helper .start_threads (threads , stop .set ):
116+ b .wait ()
117+ time .sleep (0.2 )
118+
97119
98120if __name__ == "__main__" :
99121 unittest .main ()
You can’t perform that action at this time.
0 commit comments