gh-109649: Use os.process_cpu_count() (#110165)

Replace os.cpu_count() with os.process_cpu_count() in modules:

* compileall
* concurrent.futures
* multiprocessing

Replace os.cpu_count() with os.process_cpu_count() in programs:

* _decimal deccheck.py test
* freeze.py
* multissltests.py
* python -m test (regrtest)
* wasm_build.py

Other changes:

* test.pythoninfo logs os.process_cpu_count().
* regrtest gets os.process_cpu_count() / os.cpu_count() in headers.
This commit is contained in:
Victor Stinner 2023-10-01 03:14:57 +02:00 committed by GitHub
parent 53eb9a676f
commit a46e960768
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 50 additions and 16 deletions

View file

@ -516,7 +516,11 @@ class BuildProfile:
def getenv(self) -> Dict[str, Any]:
"""Generate environ dict for platform"""
env = os.environ.copy()
env.setdefault("MAKEFLAGS", f"-j{os.cpu_count()}")
if hasattr(os, 'process_cpu_count'):
cpu_count = os.process_cpu_count()
else:
cpu_count = os.cpu_count()
env.setdefault("MAKEFLAGS", f"-j{cpu_count}")
platenv = self.host.platform.getenv(self)
for key, value in platenv.items():
if value is None: