1313except ImportError :
1414 win32api = None
1515
16- try :
17- import multiprocessing
18- except ImportError :
19- multiprocessing = None
20-
16+ import multiprocessing
2117import lit .Test
2218
2319def abort_now ():
@@ -227,8 +223,7 @@ def __init__(self, lit_config, tests):
227223 def execute_test (self , test ):
228224 return execute_test (test , self .lit_config , self .parallelism_semaphores )
229225
230- def execute_tests (self , display , jobs , max_time = None ,
231- execution_strategy = None ):
226+ def execute_tests (self , display , jobs , max_time = None ):
232227 """
233228 execute_tests(display, jobs, [max_time])
234229
@@ -249,100 +244,6 @@ def execute_tests(self, display, jobs, max_time=None,
249244 computed. Tests which were not actually executed (for any reason) will
250245 be given an UNRESOLVED result.
251246 """
252-
253- if execution_strategy == 'PROCESS_POOL' :
254- self .execute_tests_with_mp_pool (display , jobs , max_time )
255- return
256- # FIXME: Standardize on the PROCESS_POOL execution strategy and remove
257- # the other two strategies.
258-
259- use_processes = execution_strategy == 'PROCESSES'
260-
261- # Choose the appropriate parallel execution implementation.
262- consumer = None
263- if jobs != 1 and use_processes and multiprocessing :
264- try :
265- task_impl = multiprocessing .Process
266- queue_impl = multiprocessing .Queue
267- sem_impl = multiprocessing .Semaphore
268- canceled_flag = multiprocessing .Value ('i' , 0 )
269- consumer = MultiprocessResultsConsumer (self , display , jobs )
270- except :
271- # multiprocessing fails to initialize with certain OpenBSD and
272- # FreeBSD Python versions: http://bugs.python.org/issue3770
273- # Unfortunately the error raised also varies by platform.
274- self .lit_config .note ('failed to initialize multiprocessing' )
275- consumer = None
276- if not consumer :
277- task_impl = threading .Thread
278- queue_impl = queue .Queue
279- sem_impl = threading .Semaphore
280- canceled_flag = LockedValue (0 )
281- consumer = ThreadResultsConsumer (display )
282-
283- self .parallelism_semaphores = {k : sem_impl (v )
284- for k , v in self .lit_config .parallelism_groups .items ()}
285-
286- # Create the test provider.
287- provider = TestProvider (queue_impl , canceled_flag )
288- handleFailures (provider , consumer , self .lit_config .maxFailures )
289-
290- # Putting tasks into the threading or multiprocessing Queue may block,
291- # so do it in a separate thread.
292- # https://docs.python.org/2/library/multiprocessing.html
293- # e.g: On Mac OS X, we will hang if we put 2^15 elements in the queue
294- # without taking any out.
295- queuer = task_impl (target = provider .queue_tests , args = (self .tests , jobs ))
296- queuer .start ()
297-
298- # Install a console-control signal handler on Windows.
299- if win32api is not None :
300- def console_ctrl_handler (type ):
301- provider .cancel ()
302- return True
303- win32api .SetConsoleCtrlHandler (console_ctrl_handler , True )
304-
305- # Install a timeout handler, if requested.
306- if max_time is not None :
307- def timeout_handler ():
308- provider .cancel ()
309- timeout_timer = threading .Timer (max_time , timeout_handler )
310- timeout_timer .start ()
311-
312- # If not using multiple tasks, just run the tests directly.
313- if jobs == 1 :
314- run_one_tester (self , provider , consumer )
315- else :
316- # Otherwise, execute the tests in parallel
317- self ._execute_tests_in_parallel (task_impl , provider , consumer , jobs )
318-
319- queuer .join ()
320-
321- # Cancel the timeout handler.
322- if max_time is not None :
323- timeout_timer .cancel ()
324-
325- # Update results for any tests which weren't run.
326- for test in self .tests :
327- if test .result is None :
328- test .setResult (lit .Test .Result (lit .Test .UNRESOLVED , '' , 0.0 ))
329-
330- def _execute_tests_in_parallel (self , task_impl , provider , consumer , jobs ):
331- # Start all of the tasks.
332- tasks = [task_impl (target = run_one_tester ,
333- args = (self , provider , consumer ))
334- for i in range (jobs )]
335- for t in tasks :
336- t .start ()
337-
338- # Allow the consumer to handle results, if necessary.
339- consumer .handle_results ()
340-
341- # Wait for all the tasks to complete.
342- for t in tasks :
343- t .join ()
344-
345- def execute_tests_with_mp_pool (self , display , jobs , max_time = None ):
346247 # Don't do anything if we aren't going to run any tests.
347248 if not self .tests or jobs == 0 :
348249 return
0 commit comments