linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Kacur <jkacur@redhat.com>
To: rt-users <linux-rt-users@vger.kernel.org>
Cc: Clark Williams <williams@redhat.com>, John Kacur <jkacur@redhat.com>
Subject: [PATCH 3/3] hwlatdetect: make reading sample date work with python2 and python3
Date: Wed, 13 Jan 2016 15:59:47 +0100	[thread overview]
Message-ID: <1452697187-14894-4-git-send-email-jkacur@redhat.com> (raw)
In-Reply-To: <1452697187-14894-1-git-send-email-jkacur@redhat.com>

From: Clark Williams <williams@redhat.com>

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>
---
 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 c8c86ad189ca..d9ef0272d738 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):
-- 
2.4.3


      parent reply	other threads:[~2016-01-13 14:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-13 14:59 [PATCH 0/3] hwlatdetect patches John Kacur
2016-01-13 14:59 ` [PATCH 1/3] hwlatdetect: handle hwlat_detector being builtin rather than module John Kacur
2016-01-13 14:59 ` [PATCH 2/3] hwlatdetect: modify to handle python3 prints John Kacur
2016-01-13 14:59 ` John Kacur [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1452697187-14894-4-git-send-email-jkacur@redhat.com \
    --to=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).