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

Prevent pylint.run._cpu_count() from returning 0 #6903

Merged
merged 13 commits into from
Jun 11, 2022

Conversation

d1gl3
Copy link
Contributor

@d1gl3 d1gl3 commented Jun 9, 2022

Type of Changes

Type
🐛 Bug fix

Description

If --jobs=0 is passed to pylint, sometimes pylint.run._query_cpu will return 0. This later leads to a crash when passed to multiprocessing.pool.Pool as this requires more an integer >= 1 for processes.
Therefore, we just check the return value of pylint.run._query_cpu to evaluate to True instead of not None.

Closes #6902

@jacobtylerwalls jacobtylerwalls added the Needs backport Needs to be cherry-picked on the current patch version by a pylint's maintainer label Jun 9, 2022
@jacobtylerwalls jacobtylerwalls added this to the 2.14.2 milestone Jun 9, 2022
@coveralls
Copy link

coveralls commented Jun 9, 2022

Pull Request Test Coverage Report for Build 2481042270

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.006%) to 95.529%

Totals Coverage Status
Change from base Build 2480664845: 0.006%
Covered Lines: 16387
Relevant Lines: 17154

💛 - Coveralls

@github-actions

This comment has been minimized.

@d1gl3 d1gl3 marked this pull request as ready for review June 10, 2022 07:07
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

👍

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment on lines +65 to 68
if avail_cpu == 0:
avail_cpu = 1

return avail_cpu
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if avail_cpu == 0:
avail_cpu = 1
return avail_cpu
return max(avail_cpu, 1)

A little bit more explicit imo. I didn't know 0,1 == 0 so people might forget that as well later on.

Copy link
Contributor Author

@d1gl3 d1gl3 Jun 11, 2022

Choose a reason for hiding this comment

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

0,1 == 0 can't happen here, as it's getting rounded to the next int so avail_cpu is either 0 or >=1 there. Nevertheless, what I also thought of was, if just shortcircuiting the return wouldn't be the more elegant solution:

Suggested change
if avail_cpu == 0:
avail_cpu = 1
return avail_cpu
return avail_cpu or 1

But yours is more explicit though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did apply your suggestion, but this is failing due to avail_cpu being initialized as None (a valid return value for this function imo) which does not work with max. My proposal above also doesn't work here. If the function doesn't find any of the files used to determine cpus, it is just wrong to return 1 cpu available then.

Therefore I just reverse that change to my initial implementaion, only in case of avail_cpu == 0 this should be set automatically to 1

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Pierre-Sassoulas Pierre-Sassoulas merged commit 50933c5 into pylint-dev:main Jun 11, 2022
@Pierre-Sassoulas
Copy link
Member

Thank you for the great fix @d1gl3 ! It will be available in the next patch version.

@d1gl3 d1gl3 deleted the fix/issue-6902 branch June 11, 2022 19:37
@github-actions
Copy link
Contributor

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit 0854005

@Pierre-Sassoulas Pierre-Sassoulas added Backported and removed Needs backport Needs to be cherry-picked on the current patch version by a pylint's maintainer labels Jun 15, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this pull request Jun 15, 2022
Co-authored-by: Daniël van Noord <[email protected]>
Co-authored-by: Pierre Sassoulas <[email protected]>
Pierre-Sassoulas added a commit that referenced this pull request Jun 15, 2022
Co-authored-by: Daniël van Noord <[email protected]>
Co-authored-by: Pierre Sassoulas <[email protected]>
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.

Running pylint in Kubernetes Pod with --jobs=0 fails
5 participants