File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -149,6 +149,31 @@ def reader_list(b, l):
149149 with threading_helper .start_threads (threads ):
150150 pass
151151
152+ # gh-145036: race condition with list.__sizeof__()
153+ def test_list_sizeof_free_threaded_build (self ):
154+ L = []
155+
156+ def test1 ():
157+ for _ in range (100 ):
158+ L .append (1 )
159+ L .pop ()
160+
161+ def test2 ():
162+ for _ in range (100 ):
163+ L .__sizeof__ ()
164+
165+ threads = []
166+ for _ in range (4 ):
167+ threads .append (Thread (target = test1 ))
168+ threads .append (Thread (target = test2 ))
169+
170+ for t in threads :
171+ t .start ()
172+ for t in threads :
173+ t .join ()
174+
175+ self .assertEqual (len (L ), 0 )
176+
152177
153178if __name__ == "__main__" :
154179 unittest .main ()
Original file line number Diff line number Diff line change 66from test .support .import_helper import import_module
77from test .support .script_helper import assert_python_failure , assert_python_ok
88import pickle
9- from threading import Thread
109import unittest
1110
1211class ListTest (list_tests .CommonTest ):
@@ -382,30 +381,5 @@ def foo(x):
382381
383382 self .assertEqual (foo (list (range (10 ))), 45 )
384383
385- # gh-145036: race condition with list.__sizeof__()
386- def test_list_sizeof_free_threaded_build (self ):
387- L = []
388-
389- def test1 ():
390- for _ in range (100 ):
391- L .append (1 )
392- L .pop ()
393-
394- def test2 ():
395- for _ in range (100 ):
396- L .__sizeof__ ()
397-
398- threads = []
399- for _ in range (4 ):
400- threads .append (Thread (target = test1 ))
401- threads .append (Thread (target = test2 ))
402-
403- for t in threads :
404- t .start ()
405- for t in threads :
406- t .join ()
407-
408- self .assertEqual (len (L ), 0 )
409-
410384if __name__ == "__main__" :
411385 unittest .main ()
You can’t perform that action at this time.
0 commit comments