psutil note #1

psutil is a nice Python library for reading various stats about system resource use. I find the Python docs rather confusing coming from the Java land. I guess due to lack of strong typing the docs seems to be a little bit of this and a little bit of that. Sometimes something about return values is mentioned, other times nothing. In case of psutil one thing (among many others) I did not get is that the call to read CPU use percentage psutil.cpu_percent(interval=1, percpu=False) is “blocking”. Well, reading the docs right now it says that. But did not really think about that at the time I first read it. Or might have been not really clear blocking for what..

Anyway, was left wondering why a sleep of 1 second always seemed to take 2 seconds. Turns out then that using interval of 1 for the psutil means it blocks the thread for 1 second. If you do this for 20 processes you get 20 seconds delay. Leaving the interval out seems to work if calling the method at 1 second interval anyway. Probably not really but lets see..

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s