File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import signal
22import sys
33import textwrap
4+ import threading
45from test import list_tests , support
56from test .support import cpython_only
7+ from test .support import threading_helper
68from test .support .import_helper import import_module
79from test .support .script_helper import assert_python_failure , assert_python_ok
810import pickle
@@ -379,6 +381,33 @@ def foo(x):
379381
380382 self .assertEqual (foo (list (range (10 ))), 45 )
381383
384+ @unittest .skipUnless (support .Py_GIL_DISABLED and
385+ support .check_sanitizer (thread = True ),
386+ 'this test can only possibly fail with GIL disabled' )
387+ @threading_helper .reap_threads
388+ @threading_helper .requires_working_threading ()
389+ def test_free_threading (self ):
390+ def mutate (b , l ):
391+ d = [None ] * 100
392+ b .wait ()
393+
394+ for _ in range (100 ):
395+ l .extend (d )
396+ del l [:]
397+
398+ NUM_THREADS = 10
399+ barrier = threading .Barrier (len (NUM_THREADS ))
400+ threads = []
401+ l = []
402+
403+ for _ in range (NUM_THREADS ):
404+ thread = threading .Thread (target = mutate , args = (barrier , l ))
405+
406+ threads .append (thread )
407+
408+ with threading_helper .start_threads (threads ):
409+ pass
410+
382411
383412if __name__ == "__main__" :
384413 unittest .main ()
You can’t perform that action at this time.
0 commit comments