[issue17914] add os.cpu_count()

Charles-François Natali report at bugs.python.org
Mon May 13 07:52:06 CEST 2013


Charles-François Natali added the comment:

> Here is a new patch (cpu_count.patch) with a different approach:
>
>  * add a os.cpu_count() which returns the raw value (may be zero or negative if the OS returns a dummy value) and raise an OSError on error
>  * os.cpu_count() is not available on all platforms
>  * shutil.cpu_count() is the high level API using 1 as a fallback. The fallback value (which is 1 by default) is configurable, ex: shutil.cpu_count(fallback=None) returns None on os.cpu_count() error.
>  * multiprocessing.cpu_count() simply reuses shutil.cpu_count()

Do we really need cpu_count() in three places with different semantics?
Also, it doesn't belong to shutil(), which stands for shell utilities IIRC.

IMO just one version in Modules/posixmodule.c is enough (with
multiprocessing's version as an alias), there's no need to
over-engineer this.
It can return None, that's fine with me now at this point.

> I only tested my patch on Linux. It must be tested on other platforms. If nobody tests the patch on HPUX, it would be safer to remove HPUX support.

Well, HP-UX isn't officially supported, so that's reasonable.

> test_os will fail if os.cpu_count() fails. The test should be fixed to handle failures, but I prefer to start with a failing test to check if the error case occurs on a buildbot.

That's reasonable.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17914>
_______________________________________


More information about the Python-bugs-list mailing list