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

Merged
narekshaghoyandev merged 1 commit from upstream-pr/2330 into main 2026-11-28 10:48:32 +00:00
narekshaghoyandev commented 2026-11-26 13:54:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by narekshaghoyandev on 2026-11-26T13:54:05Z.


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://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193958665)
AI-assisted: yes (Gemini)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5511294011 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2330). Originally posted by [narekshaghoyandev](https://github.com/narekshaghoyandev) on 2026-11-26T13:54:05Z. --- 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://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193958665) AI-assisted: yes (Gemini)
lixonik commented 2026-11-26 15:40:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T15:40:38Z.

Review: COMMENTED


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

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6076921063 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2330#pullrequestreview-6076921063). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T15:40:38Z. **Review:** COMMENTED --- Windows 11: 12/12 pool worker checks passed. One Python 3.13+ default-size compatibility concern below. AI-assisted.
lixonik commented 2026-11-26 15:40:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T15:40:38Z.

Code review location: tools/pool_workers.py; line 19

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

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

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4710579934 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2330#discussion_r4710579934). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T15:40:38Z. **Code review location:** `tools/pool_workers.py`; line 19 ~~~~diff @@ -16,4 +16,6 @@ def process_workers(jobs): """`jobs`, lowered to the most worker processes one pool can have here.""" + if jobs is None: ~~~~ --- [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).
Rezn0r27 commented 2026-11-26 16:32:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Rezn0r27 on 2026-11-26T16:32:06Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7197771542 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2330#issuecomment-7197771542). Originally posted by [Rezn0r27](https://github.com/Rezn0r27) on 2026-11-26T16:32:06Z. --- 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.
tiguan26 commented 2026-11-27 04:42:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:42:38Z.

Review: APPROVED


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

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6083577279 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2330#pullrequestreview-6083577279). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-27T04:42:38Z. **Review:** APPROVED --- 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).
sodove commented 2026-11-28 10:12:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T10:12:55Z.


#2330 | head 850780469df3702fd3ecfdac2c053d18919c6240 | python3 -I tests/test_pool_workers.py -v, py -3.12 -I tests/test_pool_workers.py -v | red: Linux 12 run, 1 error, 2 skips / Windows 12 run, 1 error | green: Linux 10 passed, 2 skipped / Windows 12 passed | Baseline exception → pass

The new jobs=None case raised TypeError on main. I repeated the full file on native Windows so both platform-specific process-pool cases ran.

Pinned main 33db04a7010e81c40a7a6a15624525aa0c4a3a58, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4 and Windows 11 Pro, Python 3.12.10. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237749277 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2330#issuecomment-7237749277). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T10:12:55Z. --- #2330 | head `850780469df3702fd3ecfdac2c053d18919c6240` | `python3 -I tests/test_pool_workers.py -v`, `py -3.12 -I tests/test_pool_workers.py -v` | red: Linux 12 run, 1 error, 2 skips / Windows 12 run, 1 error | green: Linux 10 passed, 2 skipped / Windows 12 passed | **Baseline exception → pass** The new jobs=None case raised TypeError on main. I repeated the full file on native Windows so both platform-specific process-pool cases ran. Pinned main `33db04a7010e81c40a7a6a15624525aa0c4a3a58`, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4 and Windows 11 Pro, Python 3.12.10. Full suite: not run. AI-assisted: OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7237628300).
DadaCap commented 2026-11-28 10:48:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T10:48:33Z.


Merged, thank you @narekshaghoyandev!

What it does: pool_workers: handle jobs=None without TypeError when MAX_PROCESS_WORKERS is set

How it was checked: sodove tested this PR at head 850780469 on main 33db04a70: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (1 error); with the PR, green (12 OK).

CI: the red jobs on this PR fail the same way on main, or on the older main it was built on (the cs_dpp_cmp.asm translator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change.

Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238135868 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2330#issuecomment-7238135868). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T10:48:33Z. --- Merged, thank you @narekshaghoyandev! **What it does:** pool_workers: handle jobs=None without TypeError when MAX_PROCESS_WORKERS is set **How it was checked:** sodove tested this PR at head `850780469` on main `33db04a70`: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (1 error); with the PR, green (12 OK). **CI:** the red jobs on this PR fail the same way on main, or on the older main it was built on (the `cs_dpp_cmp.asm` translator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change. Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2330
No description provided.