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

psutil.cpu_count() should not be cached (also reflects on Process.cpu_percent()) #1055

Closed
giampaolo opened this issue May 9, 2017 · 3 comments
Labels

Comments

@giampaolo
Copy link
Owner

This is mainly a note to self because I don't remember why I did it, but cpu_count() return value is currently cached after first call. Figure out whether we want to keep it that way.

giampaolo added a commit that referenced this issue May 12, 2017
@giampaolo
Copy link
Owner Author

OK, I don't remember why but it seems we don't want to cache it.

@giampaolo
Copy link
Owner Author

Reason not to cache it, at least on Linux: it's possible to disable CPUs at runtime.
See: https://www.cyberciti.biz/faq/debian-rhel-centos-redhat-suse-hotplug-cpu/

$ echo 0 > /sys/devices/system/cpu/cpu6/online

@giampaolo giampaolo changed the title psutil.cpu_count() and cache psutil.cpu_count() should not be cached (also reflects on Process.cpu_percent()) May 19, 2017
@giampaolo
Copy link
Owner Author

Also Process.cpu_percent() should not use a cached value.

giampaolo added a commit that referenced this issue May 19, 2017
- no longer cache cpu_count() return value in Process.cpu_percent()
- in Process.cpu_percent(), guard against cpu_count() returning None and
  assume 1 instead
- add test cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant