Skip to content

Commit 5cc6ae9

Browse files
committed
gh-109276: libregrtest: limit number workers
Don't spawn more threads than the number of jobs: these worker threads would never get anything to do. Add RunTests.get_jobs() method.
1 parent 1ee50e2 commit 5cc6ae9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Lib/test/libregrtest/run_workers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,12 @@ def __init__(self, num_workers: int, runtests: RunTests,
401401
self.worker_timeout = None
402402
self.workers = None
403403

404+
jobs = self.runtests.get_jobs()
405+
if jobs is not None:
406+
# Don't spawn more threads than the number of jobs:
407+
# these worker threads would never get anything to do.
408+
self.num_workers = min(self.num_workers, jobs)
409+
404410
def start_workers(self) -> None:
405411
self.workers = [WorkerThread(index, self)
406412
for index in range(1, self.num_workers + 1)]

Lib/test/libregrtest/runtests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ def get_match_tests(self, test_name) -> FilterTuple | None:
5151
else:
5252
return None
5353

54+
def get_jobs(self):
55+
# Number of run_single_test() calls needed to run all tests.
56+
# None means that there is not bound limit (--forever option).
57+
if self.forever:
58+
return None
59+
return len(self.tests)
60+
5461
def iter_tests(self):
5562
if self.forever:
5663
while True:

0 commit comments

Comments
 (0)