@@ -105,7 +105,7 @@ def test_executor_error_file(self):
105105 self .assertTrue ("error.out" in working_directory_file_lst )
106106 os .remove (os .path .join (cwd , "error.out" ))
107107
108- def test_executor_function (self ):
108+ def test_executor_function_cancel_true (self ):
109109 fs1 = Future ()
110110 q = Queue ()
111111 q .put (
@@ -126,6 +126,51 @@ def test_executor_function(self):
126126 "execute_function" : execute_in_subprocess ,
127127 "resource_dict" : {"cores" : 1 , "cwd" : None , "cache_directory" : cache_dir },
128128 "terminate_function" : terminate_subprocess ,
129+ "cancel_futures_on_shutdown" : True ,
130+ },
131+ )
132+ process .start ()
133+ self .assertFalse (fs1 .done ())
134+ self .assertEqual (fs1 .result (), 3 )
135+ self .assertTrue (fs1 .done ())
136+ q .put ({"shutdown" : True , "wait" : True })
137+ process .join ()
138+
139+ def test_executor_function_cancel_false (self ):
140+ fs1 = Future ()
141+ q = Queue ()
142+ q .put (
143+ {
144+ "fn" : my_funct ,
145+ "args" : (),
146+ "kwargs" : {"a" : 1 , "b" : 2 },
147+ "future" : fs1 ,
148+ "resource_dict" : {},
149+ }
150+ )
151+ cache_dir = os .path .abspath ("executorlib_cache" )
152+ os .makedirs (cache_dir , exist_ok = True )
153+ process = Thread (
154+ target = execute_tasks_h5 ,
155+ kwargs = {
156+ "future_queue" : q ,
157+ "execute_function" : execute_in_subprocess ,
158+ "resource_dict" : {"cores" : 1 , "cwd" : None , "cache_directory" : cache_dir },
159+ "terminate_function" : terminate_subprocess ,
160+ "cancel_futures_on_shutdown" : False ,
161+ },
162+ )
163+ process .start ()
164+ self .assertTrue (fs1 .cancelled ())
165+ sleep (2 )
166+ process = Thread (
167+ target = execute_tasks_h5 ,
168+ kwargs = {
169+ "future_queue" : q ,
170+ "execute_function" : execute_in_subprocess ,
171+ "resource_dict" : {"cores" : 1 , "cwd" : None , "cache_directory" : cache_dir },
172+ "terminate_function" : terminate_subprocess ,
173+ "cancel_futures_on_shutdown" : False ,
129174 },
130175 )
131176 process .start ()
0 commit comments