Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate linter.config.jobs in cgroupsv2 environments #10089

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DominicLavery
Copy link

Type of Changes

Type
βœ“ πŸ› Bug fix
βœ“ ✨ New feature

Description

In containers running on cgroupv2 systems _query_cpu currently returns None. This results in sched_getaffinity being used, which will normally return all installed CPUs of the host. This can result in crashes with the error:

concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.

The changes here use the CPU quota in v2 systems. max 100000 is the default value, and will continue to result in the hosts CPU count being used.

cpu.weight (the replacement of cpu shares from v1) could also be used, but as it's impact on CPU scheduling is relative to the rest of the cgroup hierarchy it isn't possible to get an accurate value on all systems where pylint may be run. Whereas this method is reliable on any container with a CPU quota

This comment has been minimized.

Copy link

codecov bot commented Nov 23, 2024

Codecov Report

All modified and coverable lines are covered by tests βœ…

Project coverage is 95.80%. Comparing base (68cb5b3) to head (ab7b61b).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #10089   +/-   ##
=======================================
  Coverage   95.80%   95.80%           
=======================================
  Files         174      174           
  Lines       18962    18972   +10     
=======================================
+ Hits        18166    18176   +10     
  Misses        796      796           
Files with missing lines Coverage Ξ”
pylint/lint/run.py 88.48% <100.00%> (+0.89%) ⬆️
---- 🚨 Try these New Features:

Copy link
Contributor

πŸ€– According to the primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

This comment was generated for commit ab7b61b

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks for the PR. I just have some questions about structure and placement of the tests, but the code LGTM!

@@ -65,6 +65,18 @@ def _query_cpu() -> int | None:
cpu_shares = int(file.read().rstrip())
# For AWS, gives correct value * 1024.
avail_cpu = int(cpu_shares / 1024)
elif Path("/sys/fs/cgroup/cpu.max").is_file():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this take precedence over cpu.shares? If the new file is present it should probably be preferred over the old one?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't expect them to co-exist so just went with a quick grouping around v1 vs v2 but it probably makes sense just in case.
I've pushed a new commit which prefers the v2 files and I think also makes the logic a bit clearer

from pylint.testutils.utils import _test_cwd


@pytest.mark.parametrize(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this grouped with the other tests? I don't think we need a separate file as we don't follow the "file + test_file" structure

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a bit of confusion around using protected members in tests python. Figured it out and merged the tests back into the other file

@DominicLavery
Copy link
Author

Hey @DanielNoord! Thanks so much for the review. I've replied to your comments and pushed some fixes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants