diff options
author | Clark Williams <williams@redhat.com> | 2016-01-05 22:12:16 -0600 |
---|---|---|
committer | John Kacur <jkacur@redhat.com> | 2016-01-13 15:30:03 +0100 |
commit | d1ddf82849e6282889118d7a20566e70a77c5090 (patch) | |
tree | ea0043917920f8703599111fb8017832a071216d | |
parent | d7d6d35b157c7d580c3f6e00279e0a9ec7e63f9d (diff) | |
download | rt-tests-d1ddf82849e6282889118d7a20566e70a77c5090.tar.gz |
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 <williams@redhat.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
-rwxr-xr-x | src/hwlatdetect/hwlatdetect.py | 12 |
1 files 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): |