From 0b8753d24b9a37834c23faa1da705f4ed222d928 Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Wed, 16 Mar 2011 09:41:32 -0400 Subject: [PATCH] Issue #11569: use absolute path to the sysctl command in multiprocessing to ensure that it will be found regardless of the shell PATH. This ensures that multiprocessing.cpu_count works on default installs of MacOSX. --- Lib/multiprocessing/__init__.py | 5 ++++- Misc/ACKS | 1 + Misc/NEWS | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/multiprocessing/__init__.py b/Lib/multiprocessing/__init__.py index 28a5eecffd7..fdd012ea4ee 100644 --- a/Lib/multiprocessing/__init__.py +++ b/Lib/multiprocessing/__init__.py @@ -115,8 +115,11 @@ def cpu_count(): except (ValueError, KeyError): num = 0 elif 'bsd' in sys.platform or sys.platform == 'darwin': + comm = '/sbin/sysctl -n hw.ncpu' + if sys.platform == 'darwin': + comm = '/usr' + comm try: - with os.popen('sysctl -n hw.ncpu') as p: + with os.popen(comm) as p: num = int(p.read()) except ValueError: num = 0 diff --git a/Misc/ACKS b/Misc/ACKS index c7fd2ff9a03..e5ee8710b00 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -583,6 +583,7 @@ Tim Northover Joe Norton Neal Norwitz Michal Nowikowski +Steffen Daode Nurpmeso Nigel O'Brian Kevin O'Connor Tim O'Malley diff --git a/Misc/NEWS b/Misc/NEWS index c4627fac66a..d5c4699b68e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -40,6 +40,10 @@ Core and Builtins Library ------- +- Issue #11569: use absolute path to the sysctl command in multiprocessing to + ensure that it will be found regardless of the shell PATH. This ensures + that multiprocessing.cpu_count works on default installs of MacOSX. + - Issue #11501: disutils.archive_utils.make_zipfile no longer fails if zlib is not installed. Instead, the zipfile.ZIP_STORED compression is used to create the ZipFile. Patch by Natalia B. Bidart.