pool_workers: handle jobs=None without TypeError when MAX_PROCESS_WORKERS is set #2330

Open
github-bot wants to merge 1 commit from github-bot/gh-2330 into main AGit
Owner

@⁠narekshaghoyandev on GitHub · 2026-11-26 13:54 UTC · original
narekshaghoyandev:ubiq-pool-workers-none-jobs → main · +12 −0 · 2 files · 1 commits · open

Fixes a TypeError in tools/pool_workers.py:process_workers(jobs) when jobs is None and MAX_PROCESS_WORKERS is set (Windows):

  • ProcessPoolExecutor(max_workers=None) and multiprocessing.Pool(None) accept None to mean os.cpu_count(). Previously, process_workers(None) called min(None, 61) on Windows and raised TypeError.
  • When jobs is None, return None if MAX_PROCESS_WORKERS is None, otherwise min(os.cpu_count() or 1, MAX_PROCESS_WORKERS).
  • Added ProcessWorkersTest.test_none_jobs_respects_platform_limit in tests/test_pool_workers.py.

Verification

  • python3 -I -m py_compile tools/pool_workers.py tests/test_pool_workers.py passed
  • python3 -I tests/test_pool_workers.py -v passed (12 tests, 2 Windows-only skipped)
  • Negative control: new test failed with TypeError (exit 1) against unmodified ubiq/main
  • python3 -I scripts/check_no_game_data.py tools/pool_workers.py tests/test_pool_workers.py clean

Claimed in the coordination issue as: TOOLS-POOL-WORKERS-NONE-JOBS (#1608)
AI-assisted: yes (Gemini)

**@⁠narekshaghoyandev** on GitHub · 2026-11-26 13:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2330) `narekshaghoyandev:ubiq-pool-workers-none-jobs` → `main` · +12 −0 · 2 files · 1 commits · open Fixes a `TypeError` in `tools/pool_workers.py:process_workers(jobs)` when `jobs is None` and `MAX_PROCESS_WORKERS` is set (Windows): - `ProcessPoolExecutor(max_workers=None)` and `multiprocessing.Pool(None)` accept `None` to mean `os.cpu_count()`. Previously, `process_workers(None)` called `min(None, 61)` on Windows and raised `TypeError`. - When `jobs is None`, return `None` if `MAX_PROCESS_WORKERS is None`, otherwise `min(os.cpu_count() or 1, MAX_PROCESS_WORKERS)`. - Added `ProcessWorkersTest.test_none_jobs_respects_platform_limit` in `tests/test_pool_workers.py`. ### Verification - `python3 -I -m py_compile tools/pool_workers.py tests/test_pool_workers.py` passed - `python3 -I tests/test_pool_workers.py -v` passed (12 tests, 2 Windows-only skipped) - Negative control: new test failed with `TypeError` (exit 1) against unmodified `ubiq/main` - `python3 -I scripts/check_no_game_data.py tools/pool_workers.py tests/test_pool_workers.py` clean Claimed in the coordination issue as: TOOLS-POOL-WORKERS-NONE-JOBS (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) AI-assisted: yes (Gemini)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:55:55 +00:00
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 15:40 UTC · original · reviewed

Windows 11: 12/12 pool worker checks passed. One Python 3.13+ default-size compatibility concern below.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-26 15:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2330#pullrequestreview-6076921063) · **reviewed** Windows 11: 12/12 pool worker checks passed. One Python 3.13+ default-size compatibility concern below. AI-assisted.
@ -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:
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 15:40 UTC · original

[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.

**@⁠lixonik** on GitHub · 2026-11-26 15:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2330#discussion_r4710579934) [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](https://docs.python.org/3.13/library/concurrent.futures.html#concurrent.futures.ProcessPoolExecutor).
Author
Owner

@⁠Rezn0r27 on GitHub · 2026-11-26 16:32 UTC · original

Tested commit 850780469 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.

**@⁠Rezn0r27** on GitHub · 2026-11-26 16:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2330#issuecomment-7197771542) Tested commit 850780469 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.
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 04:42 UTC · original · approved these changes

Approving 850780469.

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

**@⁠tiguan26** on GitHub · 2026-11-27 04:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2330#pullrequestreview-6083577279) · **approved these changes** Approving 850780469. `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).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2330/head:github-bot/gh-2330'
git switch 'github-bot/gh-2330'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2330'
git switch 'github-bot/gh-2330'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2330'
git switch 'github-bot/gh-2330'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2330'
git switch 'main'
git merge --squash 'github-bot/gh-2330'
git switch 'main'
git merge --ff-only 'github-bot/gh-2330'
git switch 'main'
git merge 'github-bot/gh-2330'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.