Skip to content

Commit 244e37b

Browse files
authored
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
1 parent f21b230 commit 244e37b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Lib/test/test_os.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4342,8 +4342,8 @@ def test_process_cpu_count(self):
43424342
@unittest.skipUnless(hasattr(os, 'sched_setaffinity'),
43434343
"don't have sched affinity support")
43444344
def test_process_cpu_count_affinity(self):
4345-
ncpu = os.cpu_count()
4346-
if ncpu is None:
4345+
affinity1 = os.process_cpu_count()
4346+
if affinity1 is None:
43474347
self.skipTest("Could not determine the number of CPUs")
43484348

43494349
# Disable one CPU
@@ -4356,8 +4356,8 @@ def test_process_cpu_count_affinity(self):
43564356
os.sched_setaffinity(0, mask)
43574357

43584358
# test process_cpu_count()
4359-
affinity = os.process_cpu_count()
4360-
self.assertEqual(affinity, ncpu - 1)
4359+
affinity2 = os.process_cpu_count()
4360+
self.assertEqual(affinity2, affinity1 - 1)
43614361

43624362

43634363
# FD inheritance check is only useful for systems with process support.

0 commit comments

Comments
 (0)