Merge pull request #2330 from narekshaghoyandev/ubiq-pool-workers-none-jobs

pool_workers: handle jobs=None without TypeError when MAX_PROCESS_WORKERS is set
This commit is contained in:
DadaCap
2026-11-28 11:48:31 +01:00
committed by GitHub
2 changed files with 12 additions and 0 deletions

View File

@ -94,6 +94,16 @@ class ProcessWorkersTest(unittest.TestCase):
with mock.patch.object(pool_workers, "MAX_PROCESS_WORKERS", None):
self.assertEqual([pool_workers.process_workers(n) for n in (1, 61, 62, 4096)], [1, 61, 62, 4096])
def test_none_jobs_respects_platform_limit(self):
with mock.patch.object(pool_workers, "MAX_PROCESS_WORKERS", WINDOWS_LIMIT), \
mock.patch.object(os, "cpu_count", return_value=128):
self.assertEqual(pool_workers.process_workers(None), WINDOWS_LIMIT)
with mock.patch.object(pool_workers, "MAX_PROCESS_WORKERS", WINDOWS_LIMIT), \
mock.patch.object(os, "cpu_count", return_value=8):
self.assertEqual(pool_workers.process_workers(None), 8)
with mock.patch.object(pool_workers, "MAX_PROCESS_WORKERS", None):
self.assertIsNone(pool_workers.process_workers(None))
class ToolPoolSizeTest(unittest.TestCase):
"""Each tool, asked for more jobs than the limit, creates its pool at the limit and still does the work."""

View File

@ -16,4 +16,6 @@ MAX_PROCESS_WORKERS = 61 if os.name == "nt" else None
def process_workers(jobs):
"""`jobs`, lowered to the most worker processes one pool can have here."""
if jobs is None:
return None if MAX_PROCESS_WORKERS is None else min(os.cpu_count() or 1, MAX_PROCESS_WORKERS)
return jobs if MAX_PROCESS_WORKERS is None else min(jobs, MAX_PROCESS_WORKERS)