summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Wise <pabs3@bonedaddy.net>2017-05-04 21:43:54 +0800
committerPaul Wise <pabs3@bonedaddy.net>2017-05-04 21:47:22 +0800
commit83261e97e558623d402c903af3ed30a1789d453c (patch)
treeb27314b294f1e4f2cc8e7f20707044a9993803d5
parente14ecff45ee26203dfef61f9e84fe3555837066b (diff)
downloadiotop-83261e97e558623d402c903af3ed30a1789d453c.tar.gz
Support Python versions and platforms with no time.monotonic() function
Python 2 and Python 3 earlier than 3.3 do not have this function. Use the PyPI monotonic backport module if needed and available. Fall back on non-monotonic time if neither is available.
-rw-r--r--iotop/data.py11
-rw-r--r--iotop/ui.py12
2 files changed, 23 insertions, 0 deletions
diff --git a/iotop/data.py b/iotop/data.py
index a7b3278..115bb8f 100644
--- a/iotop/data.py
+++ b/iotop/data.py
@@ -28,6 +28,17 @@ import struct
import sys
import time
+# Try to ensure time.monotonic() is available
+# This normally requires Python 3.3 or later.
+# Use PyPI monotonic if needed and available.
+# Fall back on non-monotonic time if needed.
+try:
+ if not hasattr(time, 'monotonic'):
+ from monotonic import monotonic
+ time.monotonic = monotonic
+except (ImportError, RuntimeError):
+ time.monotonic = time.time
+
#
# Check for requirements:
# o Linux >= 2.6.20 with I/O accounting and VM event counters
diff --git a/iotop/ui.py b/iotop/ui.py
index d414559..c22ed1a 100644
--- a/iotop/ui.py
+++ b/iotop/ui.py
@@ -29,6 +29,18 @@ import select
import signal
import sys
import time
+
+# Try to ensure time.monotonic() is available.
+# This normally requires Python 3.3 or later.
+# Use PyPI monotonic if needed and available.
+# Fall back on non-monotonic time if needed.
+try:
+ if not hasattr(time, 'monotonic'):
+ from monotonic import monotonic
+ time.monotonic = monotonic
+except (ImportError, RuntimeError):
+ time.monotonic = time.time
+
from collections import OrderedDict
from iotop.data import find_uids, TaskStatsNetlink, ProcessList, Stats