diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-06-28 15:22:21 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2019-06-28 15:22:21 +0200 |
commit | a4fcd0916aa079fd66880d89dff489a7d4a5b7fb (patch) | |
tree | e58b3aa86e0b62688fa041d705810074343de549 /psutil/_common.py | |
parent | 0920ffbb03f18b9974a7fb1ce6e22166038b856d (diff) | |
download | psutil-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.py | 8 |
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 |