Skip to content

Detect number of CPUs with --num-workers 0 #21477

@hugovk

Description

@hugovk

Feature

Mypy 2.0 added an experimental flag:

  -n, --num-workers NUM_WORKERS
                            Number of separate mypy worker processes (experimental)

Thanks for this! Running mypy --num-workers 8 on this 8-core machine for Pillow takes 3s instead of 10s (both with no cache).

I suggest --num-workers 0 detects the number of CPUs available.

Pitch

This means the value doesn't need changing for other machines. We can put --num-workers 0 in our tox config and it will use the correct number for each machine and also for the CI.

Alternatively, --num-workers auto.

Other tools commonly use 0 or auto to use the number of available CPUs (or sometimes unlimited). Some default to this.

Further

Right now, it looks like --num-workers 0 disables the parallel machinery, and --num-workers 1 sets it up with a single worker. It could be more efficient for 1 to run without this overhead.

if options.num_workers > 0:

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions