Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b8753d

Browse files
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.
1 parent 9465d42 commit 0b8753d

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

Lib/multiprocessing/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,11 @@ def cpu_count():
115115
except (ValueError, KeyError):
116116
num = 0
117117
elif 'bsd' in sys.platform or sys.platform == 'darwin':
118+
comm = '/sbin/sysctl -n hw.ncpu'
119+
if sys.platform == 'darwin':
120+
comm = '/usr' + comm
118121
try:
119-
with os.popen('sysctl -n hw.ncpu') as p:
122+
with os.popen(comm) as p:
120123
num = int(p.read())
121124
except ValueError:
122125
num = 0

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ Tim Northover
583583
Joe Norton
584584
Neal Norwitz
585585
Michal Nowikowski
586+
Steffen Daode Nurpmeso
586587
Nigel O'Brian
587588
Kevin O'Connor
588589
Tim O'Malley

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Core and Builtins
4040
Library
4141
-------
4242

43+
- Issue #11569: use absolute path to the sysctl command in multiprocessing to
44+
ensure that it will be found regardless of the shell PATH. This ensures
45+
that multiprocessing.cpu_count works on default installs of MacOSX.
46+
4347
- Issue #11501: disutils.archive_utils.make_zipfile no longer fails if zlib is
4448
not installed. Instead, the zipfile.ZIP_STORED compression is used to create
4549
the ZipFile. Patch by Natalia B. Bidart.

0 commit comments

Comments
 (0)