From a2d6077619e71b20877d19994dc0815c7745c496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 2 Apr 2019 14:15:46 +0200 Subject: [PATCH] Fix bugs with input pipe reading (messages beginning with b'\n' or ending with whitespace) --- pipe_io_server/pipe_reader_thread.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pipe_io_server/pipe_reader_thread.py b/pipe_io_server/pipe_reader_thread.py index 2687fcd..3ba6bdc 100644 --- a/pipe_io_server/pipe_reader_thread.py +++ b/pipe_io_server/pipe_reader_thread.py @@ -8,7 +8,7 @@ from .terminate_process_on_failure import terminate_process_on_failure class PipeReaderThread(Thread): eof = b'' - stop_sequence = b'stop_reading' + stop_sequence = b'stop_reading\n' def __init__(self, pipe_path, stop_event, message_handler): super().__init__() @@ -20,11 +20,11 @@ class PipeReaderThread(Thread): def run(self): with open(self._pipe_path, 'rb') as pipe: while True: - message = pipe.readline().rstrip() + message = pipe.readline() if message in (self.eof, self.stop_sequence): self._stop_event.set() break - self._message_handler(message) + self._message_handler(message[:-1]) def stop(self): self.unblock() @@ -33,5 +33,5 @@ class PipeReaderThread(Thread): def unblock(self): with suppress(OSError): fd = osopen(self._pipe_path, O_WRONLY | O_NONBLOCK) - write(fd, self.stop_sequence + b'\n') + write(fd, self.stop_sequence) close(fd)