44from test .support import threading_helper
55
66
7- def encode_json_helper (json , worker , data , number_of_threads , number_of_json_encodings = 100 ):
7+ def encode_json_helper (
8+ json , worker , data , number_of_threads = 12 , number_of_json_encodings = 100
9+ ):
810 worker_threads = []
911 barrier = Barrier (number_of_threads )
1012 for index in range (number_of_threads ):
11- worker_threads .append (Thread (target = worker , args = [barrier , data , index ]))
13+ worker_threads .append (
14+ Thread (target = worker , args = [barrier , data , index ])
15+ )
1216 for t in worker_threads :
1317 t .start ()
1418 for ii in range (number_of_json_encodings ):
@@ -33,7 +37,6 @@ class TestJsonEncoding(CTest):
3337 # corrupt the interpreter
3438
3539 def test_json_mutating_list (self ):
36-
3740 def worker (barrier , data , index ):
3841 barrier .wait ()
3942 while data :
@@ -42,28 +45,28 @@ def worker(barrier, data, index):
4245 d .clear ()
4346 else :
4447 d .append (index )
45- d .append (index )
46- d .append (index )
47- encode_json_helper (self .json , worker , [[], []], number_of_threads = 16 )
4848
49- def test_json_mutating_dict (self ):
49+ data = [[], []]
50+ encode_json_helper (self .json , worker , data )
5051
52+ def test_json_mutating_exact_dict (self ):
5153 def worker (barrier , data , index ):
5254 barrier .wait ()
5355 while data :
5456 for d in data :
5557 if len (d ) > 5 :
5658 try :
57- d .pop (list (d )[0 ])
59+ key = list (d )[0 ]
60+ d .pop ()
5861 except (KeyError , IndexError ):
5962 pass
6063 else :
6164 d [index ] = index
6265
63- encode_json_helper (self .json , worker , [{}, {}], number_of_threads = 16 )
66+ data = [{}, {}]
67+ encode_json_helper (self .json , worker , data )
6468
6569 def test_json_mutating_mapping (self ):
66-
6770 def worker (barrier , data , index ):
6871 barrier .wait ()
6972 while data :
@@ -74,13 +77,12 @@ def worker(barrier, data, index):
7477 d .mapping .append ((index , index ))
7578
7679 data = [MyMapping (), MyMapping ()]
77- encode_json_helper (self .json , worker , data , number_of_threads = 16 )
80+ encode_json_helper (self .json , worker , data )
7881
7982
8083if __name__ == "__main__" :
8184 import time
82-
8385 t0 = time .time ()
8486 unittest .main ()
85- dt = time .time ()- t0
86- print (f' Done: { dt :.2f} ' )
87+ dt = time .time () - t0
88+ print (f" Done: { dt :.2f} " )
0 commit comments