From 1bd64c368cad923e4e84b2cc704b22c16bbf4b80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 6 Aug 2019 16:56:14 +0200 Subject: [PATCH] Fix bug where select() wouldn't block on linux (EOF) --- pipe_io_server/pipe_reader_thread.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pipe_io_server/pipe_reader_thread.py b/pipe_io_server/pipe_reader_thread.py index 487fa64..e0dd414 100644 --- a/pipe_io_server/pipe_reader_thread.py +++ b/pipe_io_server/pipe_reader_thread.py @@ -1,6 +1,6 @@ # pylint: disable=redefined-builtin,too-many-instance-attributes from contextlib import contextmanager -from os import O_NONBLOCK, O_RDONLY, open, fdopen, close, write, pipe +from os import O_NONBLOCK, O_RDONLY, O_WRONLY, open, fdopen, close, write, pipe from threading import Thread from select import select @@ -12,7 +12,7 @@ class PipeReaderThread(Thread): super().__init__(daemon=True) self._message_handler = message_handler self._pipe_path = pipe_path - self._read_fd, self._read_fp = None, None + self._read_fd, self._read_fp, self._prevent_eof_fd = None, None, None self._stop_signal_rfd, self._stop_signal_wfd = pipe() self._msg_buf = b'' self._stop_event = stop_event @@ -35,8 +35,10 @@ class PipeReaderThread(Thread): def _open(self): self._read_fd = open(self._pipe_path, O_RDONLY | O_NONBLOCK) self._read_fp = fdopen(self._read_fd, 'rb') + self._prevent_eof_fd = open(self._pipe_path, O_WRONLY) yield self._read_fp.close() + close(self._prevent_eof_fd) close(self._stop_signal_rfd) close(self._stop_signal_wfd)