Repository navigation
pool_workers: handle jobs=None without TypeError when MAX_PROCESS_WORKERS is set - #2330
narekshaghoyandev wants to merge 1 commit into
Conversation
lixonik
left a comment
There was a problem hiding this comment.
Windows 11: 12/12 pool worker checks passed. One Python 3.13+ default-size compatibility concern below.
AI-assisted.
|
|
||
| def process_workers(jobs): | ||
| """`jobs`, lowered to the most worker processes one pool can have here.""" | ||
| if jobs is None: |
There was a problem hiding this comment.
[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.
|
Tested commit 8507804 on Windows 11 (build 26300.9974) with Python 3.12. I ran py -3.12 -I tests/test_pool_workers.py -v from the PR worktree. All 12 tests passed in 1.689 seconds, with 0 skipped and exit code 0. test_none_jobs_respects_platform_limit passed, and both Windows-only tests ran successfully: test_world_build_run_jobs and test_world_lights_paths_scan. I ran the tests locally. AI-assisted setup and reporting. |
tiguan26
left a comment
There was a problem hiding this comment.
Approving 8507804.
process_workers(None) on Windows used to call min(None, 61) and raise TypeError; it now returns min(os.cpu_count() or 1, 61), the count a pool given None would pick, capped as before, and None where there is no cap.
Merged onto main d1dff7949 together with #2403, #2410, #2299, #2297 and #2286 (no conflicts), on Linux with Python 3.13. tests/test_pool_workers.py: 10 passed, 2 skipped (main: 9). AI-assisted (Claude Code, Claude Opus 5.5).
Fixes a
TypeErrorintools/pool_workers.py:process_workers(jobs)whenjobs is NoneandMAX_PROCESS_WORKERSis set (Windows):ProcessPoolExecutor(max_workers=None)andmultiprocessing.Pool(None)acceptNoneto meanos.cpu_count(). Previously,process_workers(None)calledmin(None, 61)on Windows and raisedTypeError.jobs is None, returnNoneifMAX_PROCESS_WORKERS is None, otherwisemin(os.cpu_count() or 1, MAX_PROCESS_WORKERS).ProcessWorkersTest.test_none_jobs_respects_platform_limitintests/test_pool_workers.py.Verification
python3 -I -m py_compile tools/pool_workers.py tests/test_pool_workers.pypassedpython3 -I tests/test_pool_workers.py -vpassed (12 tests, 2 Windows-only skipped)TypeError(exit 1) against unmodifiedubiq/mainpython3 -I scripts/check_no_game_data.py tools/pool_workers.py tests/test_pool_workers.pycleanClaimed in the coordination issue as: TOOLS-POOL-WORKERS-NONE-JOBS (#1608 (comment))
AI-assisted: yes (Gemini)