@@ -47,28 +47,27 @@ def run(self):
47
47
48
48
class BlockingTestMixin :
49
49
50
- def tearDown (self ):
51
- self .t = None
52
-
53
50
def do_blocking_test (self , block_func , block_args , trigger_func , trigger_args ):
54
- self .t = _TriggerThread (trigger_func , trigger_args )
55
- self .t .start ()
56
- self .result = block_func (* block_args )
57
- # If block_func returned before our thread made the call, we failed!
58
- if not self .t .startedEvent .is_set ():
59
- self .fail ("blocking function '%r' appeared not to block" %
60
- block_func )
61
- self .t .join (10 ) # make sure the thread terminates
62
- if self .t .is_alive ():
63
- self .fail ("trigger function '%r' appeared to not return" %
64
- trigger_func )
65
- return self .result
51
+ thread = _TriggerThread (trigger_func , trigger_args )
52
+ thread .start ()
53
+ try :
54
+ self .result = block_func (* block_args )
55
+ # If block_func returned before our thread made the call, we failed!
56
+ if not thread .startedEvent .is_set ():
57
+ self .fail ("blocking function '%r' appeared not to block" %
58
+ block_func )
59
+ return self .result
60
+ finally :
61
+ thread .join (10 ) # make sure the thread terminates
62
+ if thread .is_alive ():
63
+ self .fail ("trigger function '%r' appeared to not return" %
64
+ trigger_func )
66
65
67
66
# Call this instead if block_func is supposed to raise an exception.
68
67
def do_exceptional_blocking_test (self ,block_func , block_args , trigger_func ,
69
68
trigger_args , expected_exception_class ):
70
- self . t = _TriggerThread (trigger_func , trigger_args )
71
- self . t .start ()
69
+ thread = _TriggerThread (trigger_func , trigger_args )
70
+ thread .start ()
72
71
try :
73
72
try :
74
73
block_func (* block_args )
@@ -78,11 +77,11 @@ def do_exceptional_blocking_test(self,block_func, block_args, trigger_func,
78
77
self .fail ("expected exception of kind %r" %
79
78
expected_exception_class )
80
79
finally :
81
- self . t .join (10 ) # make sure the thread terminates
82
- if self . t .is_alive ():
80
+ thread .join (10 ) # make sure the thread terminates
81
+ if thread .is_alive ():
83
82
self .fail ("trigger function '%r' appeared to not return" %
84
83
trigger_func )
85
- if not self . t .startedEvent .is_set ():
84
+ if not thread .startedEvent .is_set ():
86
85
self .fail ("trigger thread ended but event never set" )
87
86
88
87
@@ -160,8 +159,11 @@ def worker(self, q):
160
159
161
160
def queue_join_test (self , q ):
162
161
self .cum = 0
162
+ threads = []
163
163
for i in (0 ,1 ):
164
- threading .Thread (target = self .worker , args = (q ,)).start ()
164
+ thread = threading .Thread (target = self .worker , args = (q ,))
165
+ thread .start ()
166
+ threads .append (thread )
165
167
for i in range (100 ):
166
168
q .put (i )
167
169
q .join ()
@@ -170,6 +172,8 @@ def queue_join_test(self, q):
170
172
for i in (0 ,1 ):
171
173
q .put (- 1 ) # instruct the threads to close
172
174
q .join () # verify that you can join twice
175
+ for thread in threads :
176
+ thread .join ()
173
177
174
178
def test_queue_task_done (self ):
175
179
# Test to make sure a queue task completed successfully.
0 commit comments