-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix Process cpu_percent on Windows #950
Conversation
Mmm that part of the code is quite old and honestly I don't remember why the logic on Windows is different. What does not convince me though it this:
I've never seen this happening. Please try to elaborate more about how you think the current implementation is broken. |
Also by doing this:
...you're changing also the UNIX implementation. Why is that necessary? |
On Windows the % of CPU of one process is calculated as:
Where delta_proc is the number of second the process has taken, and delta_time is intended to be the number of real seconds elapsed. I'm testing on a Windows 10 if that matter. I've changed the UNIX implementation to remove the definition of timer() function which would be the same on every system. I could keep the timer() function and just remove the "if POSIX" if you think it's more appropriate. |
I see. I checked now on Windows by using a busy loop process on a 2 CPUs machine and indeed it is reported as consuming around 200% where instead I would expect 100%.
|
Yes. As said I did a little more change to avoid the definition of the timer() function. Do you want me to update the PR with this change or are you going to directly commit that change ? |
Yes please update the PR with the change I paste above. While you're at it also change CREDITS and HISTORY please, then it's good to go. |
f7af607
to
e1a9376
Compare
PR updated. Thanks for your reactivity ! |
It is amazing how something this simple and important has been broken for such a long time. This is an important bugfix. Thanks for bringing it up. |
Was just about to report this as a bug; amazed at how quickly it was fixed. Thanks all! |
@giampaolo any chance this could make a point-release (i.e. |
Windows cpu_percent of Process is wrong. On a mostly idle system, a process take few percent of the CPU will be shown as using 100% by Process.cpu_percent().
This is due to the way time elapsed calculation that under Windows use the global cpu_times of user + system (ignore idle, DPC and interrupt).
This PR propose to solve this issue by using the same method as POSIX system: use the monotonic clock (if available) and fallback to time.time().