Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/test_pool_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ def test_jobs_are_lowered_only_above_the_limit(self):
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."""
Expand Down
2 changes: 2 additions & 0 deletions tools/pool_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@

def process_workers(jobs):
"""`jobs`, lowered to the most worker processes one pool can have here."""
if jobs is None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Respect the process-visible CPU count for a default pool size.

Both ProcessPoolExecutor(None) and multiprocessing.Pool(None) use os.process_cpu_count() on Python 3.13+. With a mocked Windows host count of 128 and 2 process-visible CPUs, the new helper returns 61, so callers can launch far more workers than Python's default. Prefer os.process_cpu_count where available, with os.cpu_count as the fallback for older Python. Executor documentation.

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)
Loading