@@ -129,12 +129,12 @@ def test_init_script(self):
129129 """
130130 os .write (w , b'\0 ' )
131131
132- executor = self .executor_type (initializer = initscript )
133- before_init = os .read (r , 100 )
134- fut = executor .submit (script )
135- after_init = read_msg (r )
136- fut .result ()
137- after_run = read_msg (r )
132+ with self .executor_type (initializer = initscript ) as executor :
133+ before_init = os .read (r , 100 )
134+ fut = executor .submit (script )
135+ after_init = read_msg (r )
136+ fut .result ()
137+ after_run = read_msg (r )
138138
139139 self .assertEqual (before_init , b'\0 ' )
140140 self .assertEqual (after_init , msg1 )
@@ -150,11 +150,11 @@ def test_init_func(self):
150150 r , w = self .pipe ()
151151 os .write (w , b'\0 ' )
152152
153- executor = self .executor_type (
154- initializer = write_msg , initargs = (w , msg ))
155- before = os .read (r , 100 )
156- executor .submit (mul , 10 , 10 )
157- after = read_msg (r )
153+ with self .executor_type (
154+ initializer = write_msg , initargs = (w , msg )) as executor :
155+ before = os .read (r , 100 )
156+ executor .submit (mul , 10 , 10 )
157+ after = read_msg (r )
158158
159159 self .assertEqual (before , b'\0 ' )
160160 self .assertEqual (after , msg )
@@ -260,11 +260,10 @@ def test_submit_script(self):
260260 import os
261261 os.write({ w } , __name__.encode('utf-8') + b'\\ 0')
262262 """
263- executor = self .executor_type ()
264-
265- fut = executor .submit (script )
266- res = fut .result ()
267- after = read_msg (r )
263+ with self .executor_type () as executor :
264+ fut = executor .submit (script )
265+ res = fut .result ()
266+ after = read_msg (r )
268267
269268 self .assertEqual (after , b'__main__' )
270269 self .assertIs (res , None )
@@ -278,41 +277,40 @@ def task2():
278277 spam += 1
279278 return spam
280279
281- executor = self .executor_type ()
282-
283- fut = executor .submit (task1 )
284- with self .assertRaises (_interpreters .NotShareableError ):
285- fut .result ()
280+ with self .executor_type () as executor :
281+ fut = executor .submit (task1 )
282+ with self .assertRaises (_interpreters .NotShareableError ):
283+ fut .result ()
286284
287- fut = executor .submit (task2 )
288- with self .assertRaises (_interpreters .NotShareableError ):
289- fut .result ()
285+ fut = executor .submit (task2 )
286+ with self .assertRaises (_interpreters .NotShareableError ):
287+ fut .result ()
290288
291289 def test_submit_local_instance (self ):
292290 class Spam :
293291 def __init__ (self ):
294292 self .value = True
295293
296- executor = self .executor_type ()
297- fut = executor .submit (Spam )
298- with self .assertRaises (_interpreters .NotShareableError ):
299- fut .result ()
294+ with self .executor_type () as executor :
295+ fut = executor .submit (Spam )
296+ with self .assertRaises (_interpreters .NotShareableError ):
297+ fut .result ()
300298
301299 def test_submit_instance_method (self ):
302300 class Spam :
303301 def run (self ):
304302 return True
305303 spam = Spam ()
306304
307- executor = self .executor_type ()
308- fut = executor .submit (spam .run )
309- with self .assertRaises (_interpreters .NotShareableError ):
310- fut .result ()
305+ with self .executor_type () as executor :
306+ fut = executor .submit (spam .run )
307+ with self .assertRaises (_interpreters .NotShareableError ):
308+ fut .result ()
311309
312310 def test_submit_func_globals (self ):
313- executor = self .executor_type ()
314- fut = executor .submit (get_current_name )
315- name = fut .result ()
311+ with self .executor_type () as executor :
312+ fut = executor .submit (get_current_name )
313+ name = fut .result ()
316314
317315 self .assertEqual (name , __name__ )
318316 self .assertNotEqual (name , '__main__' )
0 commit comments