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

Make cpu_percent() timeout default to 0.0 #463

Closed
giampaolo opened this issue May 23, 2014 · 3 comments
Closed

Make cpu_percent() timeout default to 0.0 #463

giampaolo opened this issue May 23, 2014 · 3 comments

Comments

@giampaolo
Copy link
Owner

From g.rodola on January 07, 2014 21:00:44

Currently we have 3 functions for calculating CPU percentage:

psutil.Process.get_cpu_percent()
psutil.cpu_percent()
psutil.cpu_times_percent()

All of them have a "timeout" parameter which defaults to 0.1 seconds.
We originally did that because waiting some time was necessary in order to get 
a meaningful return value. 

I've been regretting that decision many times though, because in applications 
which call cpu_percent* repeatedly in a loop it's very easy to forget about 
specifying timeout=0 resulting in dramatic slowdowns which are not immediately 
easy to debug.
Typical example is this, which will take *seconds* to complete:

for p in psutil.process_iter():
    pinfo = {}
    try:
        pinfo['cpu_percent'] = p.cpu_percent()
        # collect other systtem info...
    except psutil.NoSuchProcess:
        pass

Proposal  
is to just have timeout=0.0 by default and make it clear in the doc that if no 
timeout is specified the first call to *cpu_percent() will return a meaningless 
value (0.0).

Original issue: http://code.google.com/p/psutil/issues/detail?id=463

@giampaolo giampaolo self-assigned this May 23, 2014
@giampaolo
Copy link
Owner Author

From g.rodola on January 07, 2014 12:59:39

Summary: Make cpu_percent() timeout default to 0.0 (was: Make cpu_percent() default to 0.0)

@giampaolo
Copy link
Owner Author

From g.rodola on March 09, 2014 15:28:00

Fixed in revision 229c7155fd00 .

Status: FixedInHG
Labels: Milestone-2.0.0

@giampaolo
Copy link
Owner Author

From g.rodola on March 10, 2014 04:36:50

Closing out as fixed as 2.0.0 version is finally out.

Status: Fixed

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

No branches or pull requests

1 participant