Gentoo Archives: gentoo-dev

From: Doug Freed <dwfreed@×××.edu>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH 2/3] multiprocessing.eclass: Introduce get_nproc() to get no of CPUs
Date: Wed, 14 Dec 2016 18:02:06
Message-Id: CAFyXEp+MnaaYc3MZDRaRF_Go=tdu05y_-Lq1R6ma+-E-RJkdMg@mail.gmail.com
In Reply to: Re: [gentoo-dev] [PATCH 2/3] multiprocessing.eclass: Introduce get_nproc() to get no of CPUs by Nathan Zachary
1 On Wed, Dec 14, 2016 at 12:48 PM, Nathan Zachary
2 <nathanzachary@g.o> wrote:
3 > On 14/12/16 10:11, Doug Freed wrote:
4 >> On Wed, Dec 14, 2016 at 11:04 AM, Michał Górny <mgorny@g.o> wrote:
5 >>> On Wed, 14 Dec 2016 15:27:25 +0300
6 >>> Andrew Savchenko <bircoph@g.o> wrote:
7 >>>
8 >>>> On Tue, 13 Dec 2016 10:36:15 +0100 Michał Górny wrote:
9 >>>>> + nproc=$(python -c 'import multiprocessing; print(multiprocessing.cpu_count());' 2>/dev/null)
10 >>>> This is not portable. E.g. paludis users can have python-less
11 >>>> system. Adding dev-lang/python to DEPEND will be also a bad idea,
12 >>>> since this is quite heavy dependency.
13 >>> You can bikeshed potential circumstances where it wouldn't work for
14 >>> the next year. Which doesn't change that it would work quite reliably
15 >>> for the most of Gentoo users.
16 >>>
17 >>>> Since on Linux boxes nproc is from coreutils, which is in @system,
18 >>>> so looks like only *bsd setups are the problem. On FreeBSD
19 >>> ...and all other operating systems (see: Prefix).
20 >>>
21 >>>> sysctl -a | egrep -i 'hw.ncpu'
22 >>> I somehow doubt that would give me the expected number only, and I lack
23 >>> a BSD install handy to test it.
24 >> $(sysctl -n hw.ncpu)
25 >>
26 > I don't know that the sysctl command works universally:
27 >
28 > # sysctl -n hw.ncpu
29 > sysctl: cannot stat /proc/sys/hw/ncpu: No such file or directory
30 >
31
32 It's BSD-specific (Darwin may have it too, but I'm not in OS X at the
33 moment, so I can't check), which pretty much describes this branch in
34 the codepath as well. Linux users will have the nproc command from
35 coreutils.
36
37 -Doug

Replies