Skip to content

Commit

Permalink
pythongh-109649: Fix test_os.test_process_cpu_count_affinity() (pytho…
Browse files Browse the repository at this point in the history
…n#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
  • Loading branch information
vstinner authored and aisk committed Feb 11, 2024
1 parent 53e2ef9 commit 36895e1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Lib/test/test_os.py
Expand Up @@ -4342,8 +4342,8 @@ def test_process_cpu_count(self):
@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
Expand All @@ -4356,8 +4356,8 @@ def test_process_cpu_count_affinity(self):
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.
Expand Down

0 comments on commit 36895e1

Please sign in to comment.