From d1ddf82849e6282889118d7a20566e70a77c5090 Mon Sep 17 00:00:00 2001 From: Clark Williams Date: Tue, 5 Jan 2016 22:12:16 -0600 Subject: hwlatdetect: make reading sample date work with python2 and python3 Modify the sample reading code to return correct string data and to catch exceptions in non-blocking mode correctly on python{2,3} Signed-off-by: Clark Williams Signed-off-by: John Kacur --- src/hwlatdetect/hwlatdetect.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py index c8c86ad..d9ef027 100755 --- a/src/hwlatdetect/hwlatdetect.py +++ b/src/hwlatdetect/hwlatdetect.py @@ -79,15 +79,21 @@ class DebugFS(object): val = f.readline() f.close() else: - fd = os.open(path, os.O_RDONLY|os.O_NONBLOCK) + f = os.fdopen(os.open(path, os.O_RDONLY|os.O_NONBLOCK), "r") try: - val = os.read(fd, 256) + val = f.readline() except OSError as e: + print ("errno: %s" % e) if e.errno == errno.EAGAIN: val = None else: raise - os.close(fd) + except IOError as e: + if e.errno == errno.EAGAIN: + val = None + else: + raise + f.close() return val def putval(self, item, value): -- cgit 1.2.3-korg