Comments (3)
This part:
for child in process.children(recursive=True):
cpu_usage += child.cpu_percent(interval=None)
...creates a set of brand new Process
instances, upon which you immediately call cpu_percent()
. They have no knowledge of what happened before, nor they have a big enough time window to calculate a meaningful percent value, hence they return 0.
From the doc:
the first time this cpu_percent() is called with interval = 0.0 or None it will return a meaningless 0.0 value which you are supposed to ignore
from psutil.
I was assuming there is a state stored outside the psutil.Process instance, since the pcputimes.user value is consistent with the actual child that exists before its psutil twin instantiation.
And I could argue the documentation is confusing, because child.cpu_percent() is being called a first time (so as to ignore its meaningless 0.0 value), according to the PID, but not according to the psutil instance.
from psutil.
And I could argue the documentation is confusing, because child.cpu_percent() is being called a first time (so as to ignore its meaningless 0.0 value), according to the PID, but not according to the psutil instance.
I read it twice but I don't understand what you mean here. If you have suggestions on how to reword the doc please go for it.
from psutil.
Related Issues (20)
- [Linux] run "python3 -m psutil.tests", some test cases failed when nfs boot is used
- [Windows 10] psutil.process_iter() seems to be stuck
- [Linux] psutil.tests.test_linux.TestSystemVirtualMemoryAgainst tests failing
- [Linux] Get laptop charging speed (in Watts)
- process_iter(): no longer check whether PIDs have been reused HOT 1
- [Linux / FreeBSD] evaluate using `pidfd_send_signal()` for signaling processes HOT 5
- Don't build with limited API for 3.13 free-threaded build
- [macOS] active system memory is inaccurate HOT 1
- Rename Process.connections() to Process.net_connections()
- Remove deprecated `Process.memory_info_ex()`
- [macOS] psutil.Process(pid).cpu_percent calculation result is inaccurate HOT 6
- [macOS] Lacking defines in <sys/mount.h> breaks build on legacy OS X HOT 1
- [Windows] Python 3.10 wheels are missing on PYPI for psutil 5.9.8
- blkio_ticks is not supported in solaris based system. (ret['blkio_ticks'] = fields[39] # aka 'delayacct_blkio_ticks')
- [Debian 12 bookworm] Repeating spikes in temperatures samples HOT 3
- About Error `FileNotFoundError: [Errno 2] No such file or directory: '/proc/12825/stat'` the some suggest HOT 1
- [Linux] cannot import name '_psutil_linux' from partially initialized module 'psutil' (most likely due to a circular import) HOT 3
- [mac os] thread id is not the native_id
- [All] Request: Make new Release and update PyPi
- [Windows] win_service_get by PID and not by name HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from psutil.