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

CPU_PERCENT always returns zero #1095

Closed
bearrito opened this issue May 22, 2017 · 2 comments
Closed

CPU_PERCENT always returns zero #1095

bearrito opened this issue May 22, 2017 · 2 comments

Comments

@bearrito
Copy link

bearrito commented May 22, 2017

The below snippet will always show 0.0 for cpu_percent.

version: 5.2.2
OS: Ubuntu 14.04 LTS

I am running the Stress application and top shows the process at 100.00%

for proc in psutil.process_iter():
            with proc.oneshot():

                ct = proc.cpu_times()
                cp = proc.cpu_percent()

                print proc.name()

                if "stress" in proc.name():
                    print "CPU: " + str(proc.cpu_percent())
@giampaolo
Copy link
Owner

That's by design. The first call to cpu_percent() always returns 0.0 (unless you specify a timeout).
Read the doc: https://pythonhosted.org/psutil/#psutil.Process.cpu_percent

@milahu
Copy link

milahu commented Jun 23, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants