Fix bugs with input pipe reading (messages beginning with b'\n' or ending with whitespace)
This commit is contained in:
parent
22d22bc5e3
commit
a2d6077619
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user