[gnome-settings-daemon/benzea/tests-output-checker-testing] use select




commit 732b91a2df25350ab553a996ef192e9ee2c39388
Author: Benjamin Berg <bberg redhat com>
Date:   Mon Feb 15 15:34:24 2021 +0100

    use select

 tests/output_checker.py | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/tests/output_checker.py b/tests/output_checker.py
index b5f055d8..4214d97b 100644
--- a/tests/output_checker.py
+++ b/tests/output_checker.py
@@ -23,6 +23,7 @@ import io
 import re
 import time
 import threading
+import select
 
 class OutputChecker(object):
 
@@ -36,7 +37,7 @@ class OutputChecker(object):
 
         # Just to be sure, shouldn't be a problem even if we didn't set it
         fcntl.fcntl(self._pipe_fd_r, fcntl.F_SETFL,
-                    fcntl.fcntl(self._pipe_fd_r, fcntl.F_GETFL) | os.O_CLOEXEC)
+                    fcntl.fcntl(self._pipe_fd_r, fcntl.F_GETFL) | os.O_CLOEXEC | os.O_NONBLOCK)
         fcntl.fcntl(self._pipe_fd_w, fcntl.F_SETFL,
                     fcntl.fcntl(self._pipe_fd_w, fcntl.F_GETFL) | os.O_CLOEXEC)
 
@@ -47,6 +48,9 @@ class OutputChecker(object):
     def _copy(self):
         while True:
             try:
+                # Be lazy and wake up occasionally in case _pipe_fd_r became invalid
+                select.select([self._pipe_fd_r], [], [], 0.1)
+
                 r = os.read(self._pipe_fd_r, 1024)
                 if not r:
                     return
@@ -139,10 +143,6 @@ class OutputChecker(object):
         return ret
 
     def assert_closed(self, timeout=1):
-        fd = self._pipe_fd_w
-        self._pipe_fd_w = -1
-        os.close(fd)
-
         self._thread.join(timeout)
 
         if self._thread.is_alive() != False:
@@ -151,10 +151,8 @@ class OutputChecker(object):
     def force_close(self):
         os.write(1, b"force closing pipe %d" % self._pipe_fd_r);
 
-        fd = self._pipe_fd_w
-        # Write EOF
-        os.write(fd, b"")
-        self._pipe_fd_w = -1
+        fd = self._pipe_fd_r
+        self._pipe_fd_r = -1
         os.close(fd)
 
         os.write(1, b"pipe closed, waiting\n");
@@ -166,7 +164,8 @@ class OutputChecker(object):
         return self._pipe_fd_w
 
     def writer_attached(self):
-        pass
+        os.close(self._pipe_fd_w)
+        self._pipe_fd_w = -1
 
     def __del__(self):
         if self._pipe_fd_r > 0:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]