summaryrefslogtreecommitdiff
path: root/psutil/_common.py
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 /psutil/_common.py
parent0920ffbb03f18b9974a7fb1ce6e22166038b856d (diff)
downloadpsutil-a4fcd0916aa079fd66880d89dff489a7d4a5b7fb.tar.gz
fix #1546: usage percent may be rounded to 0 on Python 2.
Diffstat (limited to 'psutil/_common.py')
-rw-r--r--psutil/_common.py8
1 files changed, 4 insertions, 4 deletions
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