From c4b3b85f1252ad49480a74cc3b814ecbefc907d0 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Wed, 5 Oct 2022 11:22:01 +0300 Subject: [PATCH] fix: make it work on platforms with --- src/isolate/backends/common.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/isolate/backends/common.py b/src/isolate/backends/common.py index 44f5760..39e6cf6 100644 --- a/src/isolate/backends/common.py +++ b/src/isolate/backends/common.py @@ -115,6 +115,17 @@ def _reader(): return observer_thread +def _unblocked_pipe() -> Tuple[int, int]: + """Create a pair of unblocked pipes. This is actually + the same as os.pipe2(os.O_NONBLOCK), but that is not + available in MacOS so we have to do it manually.""" + + read_fd, write_fd = os.pipe() + os.set_blocking(read_fd, False) + os.set_blocking(write_fd, False) + return read_fd, write_fd + + @contextmanager def logged_io( stdout_hook: Callable[[str], None], @@ -124,8 +135,9 @@ def logged_io( the output from them to the given hooks.""" termination_event = threading.Event() - stdout_reader_fd, stdout_writer_fd = os.pipe2(os.O_NONBLOCK) - stderr_reader_fd, stderr_writer_fd = os.pipe2(os.O_NONBLOCK) + + stdout_reader_fd, stdout_writer_fd = _unblocked_pipe() + stderr_reader_fd, stderr_writer_fd = _unblocked_pipe() stdout_observer = _observe_reader( stdout_reader_fd,