From e8437fd435f84d1e6ed0766c2d0d9c03a0b88a0e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 15 Mar 2022 11:51:46 +0530 Subject: [PATCH] Make reading garbage more robust --- kittens/ssh/main.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kittens/ssh/main.py b/kittens/ssh/main.py index 586ba965c..b51676947 100644 --- a/kittens/ssh/main.py +++ b/kittens/ssh/main.py @@ -518,9 +518,13 @@ def drain_potential_tty_garbage(p: 'subprocess.Popen[bytes]', data_request: str) # screen termios.tcflush(tty.fileno(), termios.TCIFLUSH) data = b'' - start = time.monotonic() - while time.monotonic() - start < 1 and select([tty], [], [], 0.075)[0]: - q = os.read(tty.fileno(), io.DEFAULT_BUFFER_SIZE) + give_up_at = time.monotonic() + 1 + tty_fd = tty.fileno() + while time.monotonic() < give_up_at: + rd, wr, err = select([tty_fd], [], [tty_fd], max(0, give_up_at - time.monotonic())) + if err or not rd: + break + q = os.read(tty_fd, io.DEFAULT_BUFFER_SIZE) if not q: break data += q