-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
Pull Request Test Coverage Report for Build 2481042270
💛 - Coveralls |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
if avail_cpu == 0: | ||
avail_cpu = 1 | ||
|
||
return avail_cpu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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:
if avail_cpu == 0: | |
avail_cpu = 1 | |
return avail_cpu | |
return avail_cpu or 1 |
But yours is more explicit though.
There was a problem hiding this comment.
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
Co-authored-by: Daniël van Noord <[email protected]>
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thank you for the great fix @d1gl3 ! It will be available in the next patch version. |
🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉 This comment was generated for commit 0854005 |
Co-authored-by: Daniël van Noord <[email protected]> Co-authored-by: Pierre Sassoulas <[email protected]>
Co-authored-by: Daniël van Noord <[email protected]> Co-authored-by: Pierre Sassoulas <[email protected]>
Type of Changes
Description
If
--jobs=0
is passed to pylint, sometimespylint.run._query_cpu
will return 0. This later leads to a crash when passed tomultiprocessing.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 ofnot None
.Closes #6902