From 44a4384b5084734bedae9fd22350ec42093e366f Mon Sep 17 00:00:00 2001 From: Giorgio Salluzzo Date: Wed, 28 Jan 2026 10:10:13 +0100 Subject: [PATCH 01/10] Check if cpu.max file is non-empty before reading Fix for #478 --- loky/backend/context.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loky/backend/context.py b/loky/backend/context.py index 62795d65..78d8c317 100644 --- a/loky/backend/context.py +++ b/loky/backend/context.py @@ -145,7 +145,7 @@ def _cpu_count_cgroup(os_cpu_count): cpu_max_fname = "/sys/fs/cgroup/cpu.max" cfs_quota_fname = "/sys/fs/cgroup/cpu/cpu.cfs_quota_us" cfs_period_fname = "/sys/fs/cgroup/cpu/cpu.cfs_period_us" - if os.path.exists(cpu_max_fname): + if os.path.exists(cpu_max_fname) and os.path.getsize(cpu_max_fname) > 0: # cgroup v2 # https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html with open(cpu_max_fname) as fh: From c377a2e07e6c03c87f1fcd9260622e43decdcf7b Mon Sep 17 00:00:00 2001 From: Giorgio Salluzzo Date: Wed, 28 Jan 2026 19:01:11 +0100 Subject: [PATCH 02/10] Better fix plus couple more tests. --- loky/backend/context.py | 47 ++++++++++------ tests/test_loky_module.py | 110 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 15 deletions(-) diff --git a/loky/backend/context.py b/loky/backend/context.py index 78d8c317..b5655ec3 100644 --- a/loky/backend/context.py +++ b/loky/backend/context.py @@ -145,22 +145,39 @@ def _cpu_count_cgroup(os_cpu_count): cpu_max_fname = "/sys/fs/cgroup/cpu.max" cfs_quota_fname = "/sys/fs/cgroup/cpu/cpu.cfs_quota_us" cfs_period_fname = "/sys/fs/cgroup/cpu/cpu.cfs_period_us" - if os.path.exists(cpu_max_fname) and os.path.getsize(cpu_max_fname) > 0: + + cpu_quota_us = None + cpu_period_us = None + + if os.path.exists(cpu_max_fname): # cgroup v2 # https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html - with open(cpu_max_fname) as fh: - cpu_quota_us, cpu_period_us = fh.read().strip().split() - elif os.path.exists(cfs_quota_fname) and os.path.exists(cfs_period_fname): - # cgroup v1 - # https://www.kernel.org/doc/html/latest/scheduler/sched-bwc.html#management - with open(cfs_quota_fname) as fh: - cpu_quota_us = fh.read().strip() - with open(cfs_period_fname) as fh: - cpu_period_us = fh.read().strip() - else: - # No Cgroup CPU bandwidth limit (e.g. non-Linux platform) - cpu_quota_us = "max" - cpu_period_us = 100_000 # unused, for consistency with default values + try: + with open(cpu_max_fname) as fh: + content = fh.read().strip() + if content: + # Parse the quota and period values + parts = content.split() + if len(parts) == 2: + cpu_quota_us, cpu_period_us = parts + # If len(parts) != 2, leave as None and fall back to v1 + except (IOError, OSError): + # If we can't read the file, leave as None and fall back to v1 + pass + + # If we didn't get values from cgroup v2, try cgroup v1 + if cpu_quota_us is None or cpu_period_us is None: + if os.path.exists(cfs_quota_fname) and os.path.exists(cfs_period_fname): + # cgroup v1 + # https://www.kernel.org/doc/html/latest/scheduler/sched-bwc.html#management + with open(cfs_quota_fname) as fh: + cpu_quota_us = fh.read().strip() + with open(cfs_period_fname) as fh: + cpu_period_us = fh.read().strip() + else: + # No Cgroup CPU bandwidth limit (e.g. non-Linux platform) + cpu_quota_us = "max" + cpu_period_us = 100_000 # unused, for consistency with default values if cpu_quota_us == "max": # No active Cgroup quota on a Cgroup-capable platform @@ -172,7 +189,7 @@ def _cpu_count_cgroup(os_cpu_count): return math.ceil(cpu_quota_us / cpu_period_us) else: # pragma: no cover # Setting a negative cpu_quota_us value is a valid way to disable - # cgroup CPU bandwith limits + # cgroup CPU bandwidth limits return os_cpu_count diff --git a/tests/test_loky_module.py b/tests/test_loky_module.py index 3fd1b542..9af3d9d2 100644 --- a/tests/test_loky_module.py +++ b/tests/test_loky_module.py @@ -142,6 +142,24 @@ def test_cpu_count_cgroup_limit(): os.path.join(loky_module_path, os.pardir) ) + # Check if Docker can actually set cgroup CPU limits in this environment + # by verifying that --cpus flag writes to cgroup files + cgroup_check = check_output( + f"{docker_bin} run --rm --cpus 0.5 python:3.10 python3 -c \"" + "import os; " + "v2 = '/sys/fs/cgroup/cpu.max'; " + "v1_quota = '/sys/fs/cgroup/cpu/cpu.cfs_quota_us'; " + "v2_content = open(v2).read().strip() if os.path.exists(v2) else ''; " + "v1_content = open(v1_quota).read().strip() if os.path.exists(v1_quota) else ''; " + "print('ok' if (v2_content and v2_content != 'max') or (v1_content and v1_content != '-1') else 'skip')" + "\"", + shell=True, + text=True, + ).strip() + + if cgroup_check != 'ok': + pytest.skip("Docker doesn't properly set cgroup CPU limits in this environment") + # The following will always run using the Python 3.7 docker image. # We mount the loky source as /loky inside the container, # so it can be imported when running commands under / @@ -238,3 +256,95 @@ def test_only_physical_cores_with_user_limitation(): if cpu_count_user < cpu_count_mp: assert cpu_count() == cpu_count_user assert cpu_count(only_physical_cores=True) == cpu_count_user + + +def test_cpu_count_cgroup_empty_file(): + # Test that empty cgroup cpu.max file is handled gracefully + # and doesn't cause a ValueError when trying to unpack values + if sys.platform != "linux": + pytest.skip() + + from loky.backend.context import _cpu_count_cgroup + + with tempfile.TemporaryDirectory() as tmp_dir: + # Create an empty cpu.max file + cpu_max_path = f"{tmp_dir}/cpu.max" + with open(cpu_max_path, "w") as f: + f.write("") + + # Mock os.path.exists and open to use our test file + import loky.backend.context + old_exists = os.path.exists + old_open = open + + def mock_exists(path): + if path == "/sys/fs/cgroup/cpu.max": + return True + elif path.startswith("/sys/fs/cgroup/cpu/"): + return False + return old_exists(path) + + def mock_open_func(path, *args, **kwargs): + if path == "/sys/fs/cgroup/cpu.max": + return open(cpu_max_path, *args, **kwargs) + return old_open(path, *args, **kwargs) + + try: + # Monkeypatch os.path.exists + loky.backend.context.os.path.exists = mock_exists + # Note: We can't directly monkeypatch the builtin open in a simple way, + # so we test the function's logic indirectly by calling it + + # This should not raise ValueError even with empty file + result = _cpu_count_cgroup(mp.cpu_count()) + assert result == mp.cpu_count(), "Empty cpu.max should return os_cpu_count" + + finally: + # Restore + loky.backend.context.os.path.exists = old_exists + + +def test_cpu_count_cgroup_max_value(): + # Test that cgroup cpu.max containing just "max" is handled gracefully + if sys.platform != "linux": + pytest.skip() + + from loky.backend.context import _cpu_count_cgroup + + with tempfile.TemporaryDirectory() as tmp_dir: + # Create a cpu.max file with just "max" + cpu_max_path = f"{tmp_dir}/cpu.max" + with open(cpu_max_path, "w") as f: + f.write("max\n") + + # Mock os.path.exists to use our test file + import loky.backend.context + old_exists = os.path.exists + + def mock_exists(path): + if path == "/sys/fs/cgroup/cpu.max": + return True + elif path.startswith("/sys/fs/cgroup/cpu/"): + return False + return old_exists(path) + + try: + # Monkeypatch os.path.exists + loky.backend.context.os.path.exists = mock_exists + + # We need to also mock the file reading since the actual test won't + # have /sys/fs/cgroup/cpu.max. Let's test the logic in a unit-test style + # by directly testing the parsing logic + + # Simulate what happens when reading "max" + content = "max" + parts = content.split() + # Should have only 1 part + assert len(parts) == 1 + # The code should treat this as "max" (unlimited) + + finally: + # Restore + loky.backend.context.os.path.exists = old_exists + + From ab7a0c3a7dd39aba48240c9148c0b0358b4e6f1d Mon Sep 17 00:00:00 2001 From: Giorgio Salluzzo Date: Wed, 28 Jan 2026 19:52:14 +0100 Subject: [PATCH 03/10] Black'ed. --- loky/backend/context.py | 8 ++++++-- tests/test_loky_module.py | 18 +++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/loky/backend/context.py b/loky/backend/context.py index b5655ec3..fcae6758 100644 --- a/loky/backend/context.py +++ b/loky/backend/context.py @@ -167,7 +167,9 @@ def _cpu_count_cgroup(os_cpu_count): # If we didn't get values from cgroup v2, try cgroup v1 if cpu_quota_us is None or cpu_period_us is None: - if os.path.exists(cfs_quota_fname) and os.path.exists(cfs_period_fname): + if os.path.exists(cfs_quota_fname) and os.path.exists( + cfs_period_fname + ): # cgroup v1 # https://www.kernel.org/doc/html/latest/scheduler/sched-bwc.html#management with open(cfs_quota_fname) as fh: @@ -177,7 +179,9 @@ def _cpu_count_cgroup(os_cpu_count): else: # No Cgroup CPU bandwidth limit (e.g. non-Linux platform) cpu_quota_us = "max" - cpu_period_us = 100_000 # unused, for consistency with default values + cpu_period_us = ( + 100_000 # unused, for consistency with default values + ) if cpu_quota_us == "max": # No active Cgroup quota on a Cgroup-capable platform diff --git a/tests/test_loky_module.py b/tests/test_loky_module.py index 9af3d9d2..d23c81f6 100644 --- a/tests/test_loky_module.py +++ b/tests/test_loky_module.py @@ -145,20 +145,22 @@ def test_cpu_count_cgroup_limit(): # Check if Docker can actually set cgroup CPU limits in this environment # by verifying that --cpus flag writes to cgroup files cgroup_check = check_output( - f"{docker_bin} run --rm --cpus 0.5 python:3.10 python3 -c \"" + f'{docker_bin} run --rm --cpus 0.5 python:3.10 python3 -c "' "import os; " "v2 = '/sys/fs/cgroup/cpu.max'; " "v1_quota = '/sys/fs/cgroup/cpu/cpu.cfs_quota_us'; " "v2_content = open(v2).read().strip() if os.path.exists(v2) else ''; " "v1_content = open(v1_quota).read().strip() if os.path.exists(v1_quota) else ''; " "print('ok' if (v2_content and v2_content != 'max') or (v1_content and v1_content != '-1') else 'skip')" - "\"", + '"', shell=True, text=True, ).strip() - if cgroup_check != 'ok': - pytest.skip("Docker doesn't properly set cgroup CPU limits in this environment") + if cgroup_check != "ok": + pytest.skip( + "Docker doesn't properly set cgroup CPU limits in this environment" + ) # The following will always run using the Python 3.7 docker image. # We mount the loky source as /loky inside the container, @@ -274,6 +276,7 @@ def test_cpu_count_cgroup_empty_file(): # Mock os.path.exists and open to use our test file import loky.backend.context + old_exists = os.path.exists old_open = open @@ -297,7 +300,9 @@ def mock_open_func(path, *args, **kwargs): # This should not raise ValueError even with empty file result = _cpu_count_cgroup(mp.cpu_count()) - assert result == mp.cpu_count(), "Empty cpu.max should return os_cpu_count" + assert ( + result == mp.cpu_count() + ), "Empty cpu.max should return os_cpu_count" finally: # Restore @@ -319,6 +324,7 @@ def test_cpu_count_cgroup_max_value(): # Mock os.path.exists to use our test file import loky.backend.context + old_exists = os.path.exists def mock_exists(path): @@ -346,5 +352,3 @@ def mock_exists(path): finally: # Restore loky.backend.context.os.path.exists = old_exists - - From 5e3c27717c8786e22624e4b6d2670db600ff2ae9 Mon Sep 17 00:00:00 2001 From: Giorgio Salluzzo Date: Wed, 28 Jan 2026 19:55:01 +0100 Subject: [PATCH 04/10] Useless. --- loky/backend/context.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/loky/backend/context.py b/loky/backend/context.py index fcae6758..767192c3 100644 --- a/loky/backend/context.py +++ b/loky/backend/context.py @@ -179,9 +179,6 @@ def _cpu_count_cgroup(os_cpu_count): else: # No Cgroup CPU bandwidth limit (e.g. non-Linux platform) cpu_quota_us = "max" - cpu_period_us = ( - 100_000 # unused, for consistency with default values - ) if cpu_quota_us == "max": # No active Cgroup quota on a Cgroup-capable platform From c336f971aedeb70248feb1c3d729265a7342adf4 Mon Sep 17 00:00:00 2001 From: Giorgio Salluzzo Date: Wed, 28 Jan 2026 20:04:37 +0100 Subject: [PATCH 05/10] Fix tests. --- tests/test_loky_module.py | 88 ++++++++------------------------------- 1 file changed, 18 insertions(+), 70 deletions(-) diff --git a/tests/test_loky_module.py b/tests/test_loky_module.py index d23c81f6..3a810dd5 100644 --- a/tests/test_loky_module.py +++ b/tests/test_loky_module.py @@ -6,6 +6,7 @@ import tempfile import warnings from subprocess import check_output +from unittest.mock import patch, mock_open import pytest @@ -268,45 +269,17 @@ def test_cpu_count_cgroup_empty_file(): from loky.backend.context import _cpu_count_cgroup - with tempfile.TemporaryDirectory() as tmp_dir: - # Create an empty cpu.max file - cpu_max_path = f"{tmp_dir}/cpu.max" - with open(cpu_max_path, "w") as f: - f.write("") - - # Mock os.path.exists and open to use our test file - import loky.backend.context - - old_exists = os.path.exists - old_open = open - - def mock_exists(path): - if path == "/sys/fs/cgroup/cpu.max": - return True - elif path.startswith("/sys/fs/cgroup/cpu/"): - return False - return old_exists(path) + os_cpu_count = mp.cpu_count() - def mock_open_func(path, *args, **kwargs): - if path == "/sys/fs/cgroup/cpu.max": - return open(cpu_max_path, *args, **kwargs) - return old_open(path, *args, **kwargs) - - try: - # Monkeypatch os.path.exists - loky.backend.context.os.path.exists = mock_exists - # Note: We can't directly monkeypatch the builtin open in a simple way, - # so we test the function's logic indirectly by calling it + # Mock the file to be empty + with patch("builtins.open", mock_open(read_data="")): + with patch("os.path.exists") as mock_exists: + # cpu.max exists, but other files don't + mock_exists.side_effect = lambda path: path == "/sys/fs/cgroup/cpu.max" # This should not raise ValueError even with empty file - result = _cpu_count_cgroup(mp.cpu_count()) - assert ( - result == mp.cpu_count() - ), "Empty cpu.max should return os_cpu_count" - - finally: - # Restore - loky.backend.context.os.path.exists = old_exists + result = _cpu_count_cgroup(os_cpu_count) + assert result == os_cpu_count, "Empty cpu.max should return os_cpu_count" def test_cpu_count_cgroup_max_value(): @@ -316,39 +289,14 @@ def test_cpu_count_cgroup_max_value(): from loky.backend.context import _cpu_count_cgroup - with tempfile.TemporaryDirectory() as tmp_dir: - # Create a cpu.max file with just "max" - cpu_max_path = f"{tmp_dir}/cpu.max" - with open(cpu_max_path, "w") as f: - f.write("max\n") - - # Mock os.path.exists to use our test file - import loky.backend.context - - old_exists = os.path.exists - - def mock_exists(path): - if path == "/sys/fs/cgroup/cpu.max": - return True - elif path.startswith("/sys/fs/cgroup/cpu/"): - return False - return old_exists(path) + os_cpu_count = mp.cpu_count() - try: - # Monkeypatch os.path.exists - loky.backend.context.os.path.exists = mock_exists - - # We need to also mock the file reading since the actual test won't - # have /sys/fs/cgroup/cpu.max. Let's test the logic in a unit-test style - # by directly testing the parsing logic + # Mock the file to contain just "max" + with patch("builtins.open", mock_open(read_data="max\n")): + with patch("os.path.exists") as mock_exists: + # cpu.max exists, but other files don't + mock_exists.side_effect = lambda path: path == "/sys/fs/cgroup/cpu.max" - # Simulate what happens when reading "max" - content = "max" - parts = content.split() - # Should have only 1 part - assert len(parts) == 1 - # The code should treat this as "max" (unlimited) - - finally: - # Restore - loky.backend.context.os.path.exists = old_exists + # This should return os_cpu_count when cpu.max contains "max" + result = _cpu_count_cgroup(os_cpu_count) + assert result == os_cpu_count, "cpu.max with 'max' should return os_cpu_count" From 8ad405deef4256498c483fc055bbe57036a81485 Mon Sep 17 00:00:00 2001 From: Giorgio Salluzzo Date: Wed, 28 Jan 2026 20:05:49 +0100 Subject: [PATCH 06/10] Apply suggestion from @tomMoral Co-authored-by: Thomas Moreau --- tests/test_loky_module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_loky_module.py b/tests/test_loky_module.py index 3a810dd5..f096174e 100644 --- a/tests/test_loky_module.py +++ b/tests/test_loky_module.py @@ -163,7 +163,7 @@ def test_cpu_count_cgroup_limit(): "Docker doesn't properly set cgroup CPU limits in this environment" ) - # The following will always run using the Python 3.7 docker image. + # The following will always run using the Python 3.10 docker image. # We mount the loky source as /loky inside the container, # so it can be imported when running commands under / From 16657fb9f0e55db29f4e534b21f6298154e0a4ed Mon Sep 17 00:00:00 2001 From: Giorgio Salluzzo Date: Wed, 28 Jan 2026 20:16:35 +0100 Subject: [PATCH 07/10] No need for it. --- loky/backend/context.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/loky/backend/context.py b/loky/backend/context.py index 767192c3..2616a5ac 100644 --- a/loky/backend/context.py +++ b/loky/backend/context.py @@ -152,18 +152,14 @@ def _cpu_count_cgroup(os_cpu_count): if os.path.exists(cpu_max_fname): # cgroup v2 # https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html - try: - with open(cpu_max_fname) as fh: - content = fh.read().strip() - if content: - # Parse the quota and period values - parts = content.split() - if len(parts) == 2: - cpu_quota_us, cpu_period_us = parts - # If len(parts) != 2, leave as None and fall back to v1 - except (IOError, OSError): - # If we can't read the file, leave as None and fall back to v1 - pass + with open(cpu_max_fname) as fh: + content = fh.read().strip() + if content: + # Parse the quota and period values + parts = content.split() + if len(parts) == 2: + cpu_quota_us, cpu_period_us = parts + # If len(parts) != 2, leave as None and fall back to v1 # If we didn't get values from cgroup v2, try cgroup v1 if cpu_quota_us is None or cpu_period_us is None: From f8f98923ac885ed3ae6529b3f5a42865698b2928 Mon Sep 17 00:00:00 2001 From: Giorgio Salluzzo Date: Sat, 14 Feb 2026 09:53:01 +0100 Subject: [PATCH 08/10] Apply suggestions from code review Co-authored-by: Thomas Moreau --- loky/backend/context.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/loky/backend/context.py b/loky/backend/context.py index 2616a5ac..9d5da0c1 100644 --- a/loky/backend/context.py +++ b/loky/backend/context.py @@ -153,10 +153,8 @@ def _cpu_count_cgroup(os_cpu_count): # cgroup v2 # https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html with open(cpu_max_fname) as fh: - content = fh.read().strip() - if content: - # Parse the quota and period values - parts = content.split() + # Parse the quota and period values + parts = fh.read().strip().split() if len(parts) == 2: cpu_quota_us, cpu_period_us = parts # If len(parts) != 2, leave as None and fall back to v1 From 7c13eb36fc6af11898f9499f1f2048751385ce42 Mon Sep 17 00:00:00 2001 From: Giorgio Salluzzo Date: Sat, 14 Feb 2026 09:57:34 +0100 Subject: [PATCH 09/10] Join the new tests in a single parametrized one. --- loky/backend/context.py | 6 +++--- tests/test_loky_module.py | 36 ++++++++++-------------------------- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/loky/backend/context.py b/loky/backend/context.py index 9d5da0c1..d8cc59ba 100644 --- a/loky/backend/context.py +++ b/loky/backend/context.py @@ -155,9 +155,9 @@ def _cpu_count_cgroup(os_cpu_count): with open(cpu_max_fname) as fh: # Parse the quota and period values parts = fh.read().strip().split() - if len(parts) == 2: - cpu_quota_us, cpu_period_us = parts - # If len(parts) != 2, leave as None and fall back to v1 + if len(parts) == 2: + cpu_quota_us, cpu_period_us = parts + # If len(parts) != 2, leave as None and fall back to v1 # If we didn't get values from cgroup v2, try cgroup v1 if cpu_quota_us is None or cpu_period_us is None: diff --git a/tests/test_loky_module.py b/tests/test_loky_module.py index f096174e..a34ea3f4 100644 --- a/tests/test_loky_module.py +++ b/tests/test_loky_module.py @@ -261,8 +261,12 @@ def test_only_physical_cores_with_user_limitation(): assert cpu_count(only_physical_cores=True) == cpu_count_user -def test_cpu_count_cgroup_empty_file(): - # Test that empty cgroup cpu.max file is handled gracefully +@pytest.mark.parametrize("read_data,description", [ + ("", "empty file"), + ("max\n", "max value"), +]) +def test_cpu_count_cgroup_invalid_content(read_data, description): + # Test that invalid cgroup cpu.max file content is handled gracefully # and doesn't cause a ValueError when trying to unpack values if sys.platform != "linux": pytest.skip() @@ -271,32 +275,12 @@ def test_cpu_count_cgroup_empty_file(): os_cpu_count = mp.cpu_count() - # Mock the file to be empty - with patch("builtins.open", mock_open(read_data="")): + # Mock the file with the provided read_data + with patch("builtins.open", mock_open(read_data=read_data)): with patch("os.path.exists") as mock_exists: # cpu.max exists, but other files don't mock_exists.side_effect = lambda path: path == "/sys/fs/cgroup/cpu.max" - # This should not raise ValueError even with empty file + # This should not raise ValueError and return os_cpu_count result = _cpu_count_cgroup(os_cpu_count) - assert result == os_cpu_count, "Empty cpu.max should return os_cpu_count" - - -def test_cpu_count_cgroup_max_value(): - # Test that cgroup cpu.max containing just "max" is handled gracefully - if sys.platform != "linux": - pytest.skip() - - from loky.backend.context import _cpu_count_cgroup - - os_cpu_count = mp.cpu_count() - - # Mock the file to contain just "max" - with patch("builtins.open", mock_open(read_data="max\n")): - with patch("os.path.exists") as mock_exists: - # cpu.max exists, but other files don't - mock_exists.side_effect = lambda path: path == "/sys/fs/cgroup/cpu.max" - - # This should return os_cpu_count when cpu.max contains "max" - result = _cpu_count_cgroup(os_cpu_count) - assert result == os_cpu_count, "cpu.max with 'max' should return os_cpu_count" + assert result == os_cpu_count, f"cpu.max with {description} should return os_cpu_count" From e3e9c57967ddbba36fe85f817abe958bc0dcad90 Mon Sep 17 00:00:00 2001 From: Giorgio Salluzzo Date: Sat, 14 Feb 2026 09:58:07 +0100 Subject: [PATCH 10/10] Linting. --- tests/test_loky_module.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/test_loky_module.py b/tests/test_loky_module.py index a34ea3f4..ef1194c3 100644 --- a/tests/test_loky_module.py +++ b/tests/test_loky_module.py @@ -261,10 +261,13 @@ def test_only_physical_cores_with_user_limitation(): assert cpu_count(only_physical_cores=True) == cpu_count_user -@pytest.mark.parametrize("read_data,description", [ - ("", "empty file"), - ("max\n", "max value"), -]) +@pytest.mark.parametrize( + "read_data,description", + [ + ("", "empty file"), + ("max\n", "max value"), + ], +) def test_cpu_count_cgroup_invalid_content(read_data, description): # Test that invalid cgroup cpu.max file content is handled gracefully # and doesn't cause a ValueError when trying to unpack values @@ -279,8 +282,12 @@ def test_cpu_count_cgroup_invalid_content(read_data, description): with patch("builtins.open", mock_open(read_data=read_data)): with patch("os.path.exists") as mock_exists: # cpu.max exists, but other files don't - mock_exists.side_effect = lambda path: path == "/sys/fs/cgroup/cpu.max" + mock_exists.side_effect = ( + lambda path: path == "/sys/fs/cgroup/cpu.max" + ) # This should not raise ValueError and return os_cpu_count result = _cpu_count_cgroup(os_cpu_count) - assert result == os_cpu_count, f"cpu.max with {description} should return os_cpu_count" + assert ( + result == os_cpu_count + ), f"cpu.max with {description} should return os_cpu_count"