Merge pull request #1966 from PyCQA/limit-procs-to-file-count

avoid starting unnecessary processes when file count is limited
This commit is contained in:
Anthony Sottile 2025-02-16 13:35:04 -05:00 committed by GitHub
commit 19001f77f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View file

@ -256,6 +256,7 @@ class Manager:
exclude=self.exclude,
)
)
self.jobs = min(len(self.filenames), self.jobs)
def stop(self) -> None:
"""Stop checking files."""

View file

@ -61,6 +61,16 @@ def test_multiprocessing_cpu_count_not_implemented():
assert manager.jobs == 0
def test_jobs_count_limited_to_file_count():
style_guide = style_guide_mock()
style_guide.options.jobs = JobsArgument("4")
style_guide.options.filenames = ["file1", "file2"]
manager = checker.Manager(style_guide, finder.Checkers([], [], []), [])
assert manager.jobs == 4
manager.start()
assert manager.jobs == 2
def test_make_checkers():
"""Verify that we create a list of FileChecker instances."""
style_guide = style_guide_mock()