[gnome-settings-daemon/benzea/tests-output-checker-testing] use select
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/benzea/tests-output-checker-testing] use select
- Date: Mon, 15 Feb 2021 14:34:37 +0000 (UTC)
commit 5a41e23e79d95eaf9b0a068d8f97489970951eec
Author: Benjamin Berg <bberg redhat com>
Date: Mon Feb 15 15:34:24 2021 +0100
use select
tests/output_checker.py | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
---
diff --git a/tests/output_checker.py b/tests/output_checker.py
index b5f055d8..ddaefbdb 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,7 @@ class OutputChecker(object):
def _copy(self):
while True:
try:
+ select.select([self._pipe_fd_r], [], [])
r = os.read(self._pipe_fd_r, 1024)
if not r:
return
@@ -139,10 +141,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 +149,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 +162,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]