mstar.utils.cpus

mstar.utils.cpus#

How many CPUs this process can keep busy at once.

os.cpu_count() reports the host’s CPUs. In a container the cgroup CPU quota can be far smaller, and a thread pool sized to the host then runs more threads than the quota lets run, so a fork-join op waits on whichever thread the scheduler parked.

Functions

cgroup_cpu_quota([root, proc_cgroup])

The tightest cgroup v2 cpu.max quota over this process's cgroup and its ancestors, in CPUs; None when no level sets one (or cgroup v2 is absent).

usable_cpus()

CPUs this process may run on (its affinity, else os.cpu_count()), capped by the cgroup quota rounded down.

mstar.utils.cpus.cgroup_cpu_quota(root=_CGROUP_ROOT, proc_cgroup='/proc/self/cgroup')[source]#

The tightest cgroup v2 cpu.max quota over this process’s cgroup and its ancestors, in CPUs; None when no level sets one (or cgroup v2 is absent).

Parameters:
Return type:

float | None

mstar.utils.cpus.usable_cpus()[source]#

CPUs this process may run on (its affinity, else os.cpu_count()), capped by the cgroup quota rounded down. At least 1.

Return type:

int