summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-11-03 23:53:18 (GMT)
committerGitHub <noreply@github.com>2023-11-03 23:53:18 (GMT)
commit244e37b22a826eeb37bc057193bbff7138bc6ac3 (patch)
tree0b0a03203aa820c7e436d96d5a7d815f2190bc85 /Lib
parentf21b23058e01515166a6b61fdea01864ad9c0572 (diff)
downloadcpython-244e37b22a826eeb37bc057193bbff7138bc6ac3.zip
cpython-244e37b22a826eeb37bc057193bbff7138bc6ac3.tar.gz
cpython-244e37b22a826eeb37bc057193bbff7138bc6ac3.tar.bz2
gh-109649: Fix test_os.test_process_cpu_count_affinity() (#111689)
When CPUs are isolated on Linux, os.process_cpu_count() is smaller than os.cpu_count(). Fix the test for this case. Example with "isolcpus=5,11 rcu_nocbs=5,11" options passed to a Linux command line to isolated two logical CPUs: $ ./python -c 'import os; print(os.process_cpu_count(), "/", os.cpu_count())' 10 / 12
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_os.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 22e40d9..b357797 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -4342,8 +4342,8 @@ class CPUCountTests(unittest.TestCase):
@unittest.skipUnless(hasattr(os, 'sched_setaffinity'),
"don't have sched affinity support")
def test_process_cpu_count_affinity(self):
- ncpu = os.cpu_count()
- if ncpu is None:
+ affinity1 = os.process_cpu_count()
+ if affinity1 is None:
self.skipTest("Could not determine the number of CPUs")
# Disable one CPU
@@ -4356,8 +4356,8 @@ class CPUCountTests(unittest.TestCase):
os.sched_setaffinity(0, mask)
# test process_cpu_count()
- affinity = os.process_cpu_count()
- self.assertEqual(affinity, ncpu - 1)
+ affinity2 = os.process_cpu_count()
+ self.assertEqual(affinity2, affinity1 - 1)
# FD inheritance check is only useful for systems with process support.