11import unittest
2- from threading import Thread , Barrier
2+ from threading import Thread , Barrier , Event
33from test .support import threading_helper
44
55
@@ -38,19 +38,18 @@ def test_contains_mutate(self):
3838 """Test set contains operation combined with mutation."""
3939 barrier = Barrier (2 , timeout = 2 )
4040 s = set ()
41- done = False
41+ done = Event ()
4242
4343 NUM_LOOPS = 1000
4444
4545 def read_set ():
4646 barrier .wait ()
47- while not done :
47+ while not done . is_set () :
4848 for i in range (self .SET_SIZE ):
4949 item = i >> 1
5050 result = item in s
5151
5252 def mutate_set ():
53- nonlocal done
5453 barrier .wait ()
5554 for i in range (NUM_LOOPS ):
5655 s .clear ()
@@ -60,7 +59,7 @@ def mutate_set():
6059 s .discard (j )
6160 # executes the set_swap_bodies() function
6261 s .__iand__ (set (k for k in range (10 , 20 )))
63- done = True
62+ done . set ()
6463
6564 threads = [Thread (target = read_set ), Thread (target = mutate_set )]
6665 for t in threads :
@@ -70,7 +69,7 @@ def mutate_set():
7069
7170 def test_contains_frozenset (self ):
7271 barrier = Barrier (3 , timeout = 2 )
73- done = False
72+ done = Event ()
7473
7574 NUM_LOOPS = 1_000
7675
@@ -80,20 +79,19 @@ def test_contains_frozenset(self):
8079
8180 def mutate_set ():
8281 barrier .wait ()
83- while not done :
82+ while not done . is_set () :
8483 s .add (0 )
8584 s .add (1 )
8685 s .clear ()
8786
8887 def read_set ():
89- nonlocal done
9088 barrier .wait ()
9189 container = frozenset ([frozenset ([0 ])])
9290 self .assertTrue (set ([0 ]) in container )
9391 for _ in range (NUM_LOOPS ):
9492 # Will return True when {0} is the key and False otherwise
9593 result = s in container
96- done = True
94+ done . set ()
9795
9896 threads = [
9997 Thread (target = read_set ),
0 commit comments