summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-06-28 15:22:21 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2019-06-28 15:22:21 +0200
commita4fcd0916aa079fd66880d89dff489a7d4a5b7fb (patch)
treee58b3aa86e0b62688fa041d705810074343de549
parent0920ffbb03f18b9974a7fb1ce6e22166038b856d (diff)
downloadpsutil-a4fcd0916aa079fd66880d89dff489a7d4a5b7fb.tar.gz
fix #1546: usage percent may be rounded to 0 on Python 2.
-rw-r--r--HISTORY.rst1
-rw-r--r--psutil/_common.py8
2 files changed, 5 insertions, 4 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 1f83b02c..733ab038 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -13,6 +13,7 @@ XXXX-XX-XX
always turned into enums.
- 1536_: [NetBSD] process cmdline() erroneously raise ZombieProcess error if
cmdline has non encodable chars.
+- 1546_: usage percent may be rounded to 0 on Python 2.
5.6.3
=====
diff --git a/psutil/_common.py b/psutil/_common.py
index 4a006c1d..126d9d6f 100644
--- a/psutil/_common.py
+++ b/psutil/_common.py
@@ -266,12 +266,12 @@ if AF_UNIX is not None:
def usage_percent(used, total, round_=None):
"""Calculate percentage usage of 'used' against 'total'."""
try:
- ret = (used / total) * 100
+ ret = (float(used) / total) * 100
except ZeroDivisionError:
- ret = 0.0 if isinstance(used, float) or isinstance(total, float) else 0
- if round_ is not None:
- return round(ret, round_)
+ return 0.0
else:
+ if round_ is not None:
+ ret = round(ret, round_)
return ret