Skip to content

cpu_percent still samples inside oneshot() - #2986

Open
gyanu2507 wants to merge 1 commit into
giampaolo:masterfrom
gyanu2507:cpu-percent-oneshot
Open

cpu_percent still samples inside oneshot()#2986
gyanu2507 wants to merge 1 commit into
giampaolo:masterfrom
gyanu2507:cpu-percent-oneshot

Conversation

@gyanu2507

Copy link
Copy Markdown

Summary

Description

cpu_percent(interval=0.5) inside oneshot() always returned 0.0. oneshot caches cpu_times(), so both samples were the same snapshot.

This reads live CPU times for those two samples and restores the oneshot cache afterwards, so name() / cpu_times() still share a snapshot.

oneshot() caches cpu_times(), so both ends of the interval were the same
reading and the method always returned 0.0.
@github-actions github-actions Bot added the bug type label Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug type

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Linux] cpu_percent does not work within oneshot context manager as expected

1 participant