1616from test .support import os_helper
1717from test .support import TestStats
1818
19- from test .libregrtest .cmdline import Namespace
2019from test .libregrtest .main import Regrtest
2120from test .libregrtest .runtest import (
2221 run_single_test , TestResult , State , PROGRESS_MIN_TIME ,
@@ -150,14 +149,13 @@ class ExitThread(Exception):
150149 pass
151150
152151
153- class TestWorkerProcess (threading .Thread ):
154- def __init__ (self , worker_id : int , runner : "MultiprocessTestRunner " ) -> None :
152+ class WorkerThread (threading .Thread ):
153+ def __init__ (self , worker_id : int , runner : "RunWorkers " ) -> None :
155154 super ().__init__ ()
156155 self .worker_id = worker_id
157156 self .runtests = runner .runtests
158157 self .pending = runner .pending
159158 self .output = runner .output
160- self .ns = runner .ns
161159 self .timeout = runner .worker_timeout
162160 self .regrtest = runner .regrtest
163161 self .current_test_name = None
@@ -167,7 +165,7 @@ def __init__(self, worker_id: int, runner: "MultiprocessTestRunner") -> None:
167165 self ._stopped = False
168166
169167 def __repr__ (self ) -> str :
170- info = [f'TestWorkerProcess #{ self .worker_id } ' ]
168+ info = [f'WorkerThread #{ self .worker_id } ' ]
171169 if self .is_alive ():
172170 info .append ("running" )
173171 else :
@@ -203,7 +201,7 @@ def _kill(self) -> None:
203201 else :
204202 popen .kill ()
205203 except ProcessLookupError :
206- # popen.kill(): the process completed, the TestWorkerProcess thread
204+ # popen.kill(): the process completed, the WorkerThread thread
207205 # read its exit status, but Popen.send_signal() read the returncode
208206 # just before Popen.wait() set returncode.
209207 pass
@@ -362,7 +360,7 @@ def _runtest(self, test_name: str) -> MultiprocessResult:
362360
363361 def run (self ) -> None :
364362 fail_fast = self .runtests .fail_fast
365- fail_env_changed = self .ns .fail_env_changed
363+ fail_env_changed = self .runtests .fail_env_changed
366364 while not self ._stopped :
367365 try :
368366 try :
@@ -394,10 +392,10 @@ def _wait_completed(self) -> None:
394392 f"{ exc !r} " )
395393
396394 def wait_stopped (self , start_time : float ) -> None :
397- # bpo-38207: MultiprocessTestRunner .stop_workers() called self.stop()
395+ # bpo-38207: RunWorkers .stop_workers() called self.stop()
398396 # which killed the process. Sometimes, killing the process from the
399397 # main thread does not interrupt popen.communicate() in
400- # TestWorkerProcess thread. This loop with a timeout is a workaround
398+ # WorkerThread thread. This loop with a timeout is a workaround
401399 # for that.
402400 #
403401 # Moreover, if this method fails to join the thread, it is likely
@@ -417,7 +415,7 @@ def wait_stopped(self, start_time: float) -> None:
417415 break
418416
419417
420- def get_running (workers : list [TestWorkerProcess ]) -> list [TestWorkerProcess ]:
418+ def get_running (workers : list [WorkerThread ]) -> list [str ]:
421419 running = []
422420 for worker in workers :
423421 current_test_name = worker .current_test_name
@@ -427,18 +425,17 @@ def get_running(workers: list[TestWorkerProcess]) -> list[TestWorkerProcess]:
427425 if dt >= PROGRESS_MIN_TIME :
428426 text = '%s (%s)' % (current_test_name , format_duration (dt ))
429427 running .append (text )
430- return running
428+ if not running :
429+ return None
430+ return f"running ({ len (running )} ): { ', ' .join (running )} "
431431
432432
433- class MultiprocessTestRunner :
434- def __init__ (self , regrtest : Regrtest , runtests : RunTests ) -> None :
435- ns = regrtest .ns
436-
433+ class RunWorkers :
434+ def __init__ (self , regrtest : Regrtest , runtests : RunTests , num_workers : int ) -> None :
437435 self .regrtest = regrtest
436+ self .log = regrtest .log
437+ self .num_workers = num_workers
438438 self .runtests = runtests
439- self .rerun = runtests .rerun
440- self .log = self .regrtest .log
441- self .ns = ns
442439 self .output : queue .Queue [QueueOutput ] = queue .Queue ()
443440 tests_iter = runtests .iter_tests ()
444441 self .pending = MultiprocessIterator (tests_iter )
@@ -453,9 +450,8 @@ def __init__(self, regrtest: Regrtest, runtests: RunTests) -> None:
453450 self .workers = None
454451
455452 def start_workers (self ) -> None :
456- use_mp = self .ns .use_mp
457- self .workers = [TestWorkerProcess (index , self )
458- for index in range (1 , use_mp + 1 )]
453+ self .workers = [WorkerThread (index , self )
454+ for index in range (1 , self .num_workers + 1 )]
459455 msg = f"Run tests in parallel using { len (self .workers )} child processes"
460456 if self .timeout :
461457 msg += (" (timeout: %s, worker timeout: %s)"
@@ -489,10 +485,11 @@ def _get_result(self) -> QueueOutput | None:
489485 except queue .Empty :
490486 pass
491487
492- # display progress
493- running = get_running (self .workers )
494- if running and not pgo :
495- self .log ('running: %s' % ', ' .join (running ))
488+ if not pgo :
489+ # display progress
490+ running = get_running (self .workers )
491+ if running :
492+ self .log (running )
496493
497494 # all worker threads are done: consume pending results
498495 try :
@@ -510,9 +507,10 @@ def display_result(self, mp_result: MultiprocessResult) -> None:
510507 text += ' (%s)' % mp_result .err_msg
511508 elif (result .duration >= PROGRESS_MIN_TIME and not pgo ):
512509 text += ' (%s)' % format_duration (result .duration )
513- running = get_running (self .workers )
514- if running and not pgo :
515- text += ' -- running: %s' % ', ' .join (running )
510+ if not pgo :
511+ running = get_running (self .workers )
512+ if running :
513+ text += f' -- { running } '
516514 self .regrtest .display_progress (self .test_index , text )
517515
518516 def _process_result (self , item : QueueOutput ) -> bool :
@@ -537,9 +535,9 @@ def _process_result(self, item: QueueOutput) -> bool:
537535
538536 return result
539537
540- def run_tests (self ) -> None :
538+ def run (self ) -> None :
541539 fail_fast = self .runtests .fail_fast
542- fail_env_changed = self .ns .fail_env_changed
540+ fail_env_changed = self .runtests .fail_env_changed
543541
544542 self .start_workers ()
545543
@@ -566,10 +564,6 @@ def run_tests(self) -> None:
566564 self .stop_workers ()
567565
568566
569- def run_tests_multiprocess (regrtest : Regrtest , runtests : RunTests ) -> None :
570- MultiprocessTestRunner (regrtest , runtests ).run_tests ()
571-
572-
573567class EncodeTestResult (json .JSONEncoder ):
574568 """Encode a TestResult (sub)class object into a JSON dict."""
575569
0 commit comments