From e523cbdab33884597a66214b1969eba794c0b567 Mon Sep 17 00:00:00 2001 From: jacekk Date: Fri, 21 Jun 2024 13:46:00 +0000 Subject: [PATCH] machine.channel Fix hanging on read_until_prompt. On some devices, logs may be printed just after the prompt. In such case prompt lands in the middle of a buffer, not at the end. This change is to avoid infinite hanging in such cases. Signed-off-by: jacekk --- tbot/machine/channel/channel.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tbot/machine/channel/channel.py b/tbot/machine/channel/channel.py index f313e32d..d49c539f 100644 --- a/tbot/machine/channel/channel.py +++ b/tbot/machine/channel/channel.py @@ -914,9 +914,10 @@ def read_until_prompt( buf += new if isinstance(self.prompt, bytes): - if buf.endswith(self.prompt): + index = buf.find(self.prompt) + if index > -1: return ( - buf[: -len(self.prompt)] + buf[:index] .decode("utf-8", errors="replace") .replace("\r\n", "\n") .replace("\n\r", "\n")