Page MenuHome

A.N.T Landscape add-on broken after psutil API change
ClosedPublic

Authored by Predrag Ivanović (pedja) on Apr 29 2019, 2:43 PM.

Diff Detail

Event Timeline

ant_landscape/stats.py
28

Code Style: There are missing spaces.

Also, better use something like hasattr(self.process, "get_cpu_time"). This should work as well, right?
Additionally it would be nice to put a comment there to explain why this check is necessary.

Can you get the current version from psutil? Maybe then the check could be something like if psutil.version < ....

ant_landscape/stats.py
28

Also, better use something like hasattr(self.process, "get_cpu_time"). This should work as well, right?

If I am reading Python docs correctly, yes.
Since it returns true/false, no need for 'callable' then, correct?

Can you get the current version from psutil? Maybe then the check could be something like if psutil.version < ....

You can, but I can't figure out when the change happened.
So checking attribute name looks like a more robust solution?

Update based on code review:

  • Add comment to explain the change
  • Use hasattr() instead of getattr()
  • Hopefully fix code style issues

Good, will merge it tomorrow.

This revision is now accepted and ready to land.Apr 29 2019, 6:14 PM
Ray Molenkamp (LazyDodo) added inline comments.
ant_landscape/stats.py
30

Typo get_cpu_time vs get_cpu_times ?

Good catch..... Will fix that when merging.

Fix typo in attribute name

Just for reference, the API was changed in version 2.0.
So this bug exists for more than 5 years^^

https://github.com/giampaolo/psutil/blob/master/HISTORY.rst#200

This revision was automatically updated to reflect the committed changes.