Skip to content

os.cpu_count() recommends non-portable len(os.sched_getaffinity(0)) to get usable CPUs #105972

@cquike

Description

@cquike

Documentation

The documentation of os.cpu_count() mentions that to get the the number of usable CPUs one can use len(os.sched_getaffinity(0)). However that's not available in all platforms, for instance in macOS.
For Unix platforms a better approach would be to use os.sysconf('SC_NPROCESSORS_ONLN'), which is also not fully standard, however at least it has been proposed for the next POSIX standard (https://www.austingroupbugs.net/view.php?id=339) and is currently available in many UNIX platforms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions