From: Ronald Oussoren Date: Wed, 16 Mar 2011 13:47:15 +0000 (-0400) Subject: Issue #11569: use absolute path to the sysctl command in multiprocessing to X-Git-Tag: v2.7.2rc1~245 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2ab5994dbe8934564f1ac0b3be1e6d98235e6773;p=python 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. Patch by Steffen Daode Nurpmeso. --- diff --git a/Lib/multiprocessing/__init__.py b/Lib/multiprocessing/__init__.py index 4e1b6aedd1..4963293bd9 100644 --- a/Lib/multiprocessing/__init__.py +++ b/Lib/multiprocessing/__init__.py @@ -116,8 +116,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 a1f620f924..5d617daa36 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -587,6 +587,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 af1ba7f4fc..0c5b7f2631 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -43,6 +43,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 #11500: Fixed a bug in the os x proxy bypass code for fully qualified IP addresses in the proxy exception list.