This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Yogesh.Chaudhari, dilettant, ezio.melotti, kushal.das, nedbat, neologix, pitrou, r.david.murray, serhiy.storchaka, trent, vstinner
Date 2013-05-12.23:56:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1368402972.0.0.444255584628.issue17914@psf.upfronthosting.co.za>
In-reply-to
Content
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()

So os.cpu_count() as a well defined behaviour, and shutil.cpu_count() is the convinient API.

My patch is based on issue17914-4.patch and so also on Trent Nelson's code.

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.

It looks like Trent's code was not tested, I don't think that his code works on platforms other than Windows.

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.
History
Date User Action Args
2013-05-12 23:56:12vstinnersetrecipients: + vstinner, pitrou, nedbat, trent, ezio.melotti, r.david.murray, neologix, serhiy.storchaka, kushal.das, dilettant, Yogesh.Chaudhari
2013-05-12 23:56:12vstinnersetmessageid: <1368402972.0.0.444255584628.issue17914@psf.upfronthosting.co.za>
2013-05-12 23:56:11vstinnerlinkissue17914 messages
2013-05-12 23:56:11vstinnercreate