-
-
Notifications
You must be signed in to change notification settings - Fork 154
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make CPU cores count more tolerant towards system command errors #1733
Make CPU cores count more tolerant towards system command errors #1733
Conversation
484ace2
to
2be8c78
Compare
Could you please past an error here?
|
Sure, I just edited the description above; unfortunately the message is not really relevant. 馃槙 |
$hasNproc = trim(@shell_exec('command -v nproc')); | ||
try { | ||
// for Linux | ||
$hasNproc = trim(@shell_exec('command -v nproc')); |
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.
one issue I see with this try/catch is that it's unclear which statement you really expect to throw
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.
Well the idea is mostly not to block i.e. Mac/Windows users when the Linux command does fail, to allow the next part of the function to run without trouble.
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 was more referring at the statement causing failure, here I doubt that anything apart from the shell exec is suppose to throw right?
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.
Right. Actually if any of the two shell_exec
calls fails, it should be caught IMO, no matter which one. WDYT?
if (is_int($cpuCount)) { | ||
return $cpuCount; | ||
} | ||
} catch (ExecException) { |
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.
That being said I'd personally find unexpected that you ask several threads and end up with only one... but that's out of the scope of this PR
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.
Yes, maybe we could add a notice/warning if all commands failed? WDYT?
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.
馃憤 (would do so in a different PR 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.
When/if this PR is merged I'll submit a new one where we can discuss this. 馃槈
In addition to what @theofidry said please consider using the unsafe variant of |
Sure, if others agree I see no problem to switch to the native |
@sanmai @maks-rafalko After giving it some thought, the safe version of |
Ok, let's get it merged, seems like we all ok with either safe of unsafe versions. Other comments are not related to this fix. Thank you @romm |
Running Infection with the new
--threads=max
option was leading to an error on my local MacOS.This fix is quite opinionated, if you see a better way of doing this I'd be happy to follow your recommendations. 馃槈
This is the error that was returned: