Skip to content

Commit

Permalink
fix: make it work on platforms with
Browse files Browse the repository at this point in the history
  • Loading branch information
isidentical committed Oct 5, 2022
1 parent 8c5ebd1 commit c4b3b85
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/isolate/backends/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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,
Expand Down

0 comments on commit c4b3b85

Please sign in to comment.