Skip to content

run --process/-n accepts 'cpu' to use one subprocess per CPU - #492

Open
chiliec wants to merge 1 commit into
pydoit:masterfrom
chiliec:num-process-cpu
Open

chiliec wants to merge 1 commit into
pydoit:masterfrom
chiliec:num-process-cpu

Conversation

@chiliec

@chiliec chiliec commented Sep 21, 2026

Copy link
Copy Markdown

Closes #400.

Implements the -n cpu form that was agreed in the issue thread: --process/-n now accepts cpu in addition to an integer, and resolves it to os.cpu_count(). The default stays 0 (no parallel execution), so nothing changes for existing invocations.

$ doit -n cpu
$ doit -n cpu -P thread

Changes:

  • doit/cmd_run.py: num_process_type converter ('cpu'os.cpu_count() or 1, otherwise int); option type and help text updated.
  • doit/cmdparse.py: the "Error parsing parameter" message now prints the type's __name__ instead of its repr, so a callable type renders as (num_process_type) rather than <function ... at 0x...>.
  • tests/test_cmd_run.py: test_num_process covering default, integer, cpu, and an invalid value.
  • CHANGES, doc/cmd-run.rst.

Validation (Python 3.11, rut 0.4.0):

  • rut tests/test_cmd_run.py before the change: test_num_process fails with invalid literal for int() with base 10: 'cpu'; after: 15 passed.
  • Full rut: 830 passed, 1 failed — tests/test___main__.py::TestMain.test_execute, which fails identically on a clean checkout of da5a25f here (it imports the repo's dodo.py, whose imports are not installed in my env), so unrelated to this change.
  • Manual: doit -n cpu and doit -n 2 -P thread on a two-task dodo.py run both tasks; doit -n xyz exits 3 with Error parsing parameter 'num_process' (num_process_type). expected an integer or 'cpu', got 'xyz'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

num_process = num_cpus

1 participant