Skip to content

Commit 45f263f

Browse files
committed
Address requested review changes
1 parent 0dd33d6 commit 45f263f

2 files changed

Lines changed: 7 additions & 31 deletions

File tree

psutil/_pslinux.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,9 +2148,13 @@ def _get_eligible_cpus(
21482148
# See: https://github.com/giampaolo/psutil/issues/956
21492149
data = self._read_status_file()
21502150
if match := _re.search(data):
2151-
return _parse_cpulist(decode(match.group(1)))
2152-
else:
2153-
return list(range(len(per_cpu_times())))
2151+
try:
2152+
return _parse_cpulist(decode(match.group(1)))
2153+
except ValueError as err:
2154+
debug(
2155+
f"can't parse Cpus_allowed_list ({err}); falling back"
2156+
)
2157+
return list(range(len(per_cpu_times())))
21542158

21552159
@wrap_exceptions
21562160
def cpu_affinity_set(self, cpus):

tests/test_linux.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -708,34 +708,6 @@ def test_no_space_after_colon(self):
708708
# =====================================================================
709709

710710

711-
class TestParseCpuList(LinuxTestCase):
712-
def test_valid(self):
713-
cases = [
714-
("0", [0]),
715-
("0-3", [0, 1, 2, 3]),
716-
("0-3,8", [0, 1, 2, 3, 8]),
717-
(
718-
"0-3,8-11,14,17",
719-
[0, 1, 2, 3, 8, 9, 10, 11, 14, 17],
720-
),
721-
(" 0-0 ", [0]),
722-
("", []),
723-
]
724-
for value, expected in cases:
725-
with self.subTest(value=value):
726-
assert _parse_cpulist(value) == expected
727-
728-
def test_invalid_integer(self):
729-
for value in ("x", "0-x", "0-1-2"):
730-
with self.subTest(value=value):
731-
with pytest.raises(ValueError):
732-
_parse_cpulist(value)
733-
734-
def test_reversed_range(self):
735-
with pytest.raises(ValueError, match="invalid CPU range"):
736-
_parse_cpulist("3-1")
737-
738-
739711
class TestCpuCountLogical(LinuxTestCase):
740712
@skipif(
741713
not os.path.exists("/sys/devices/system/cpu/online"),

0 commit comments

Comments
 (0)