Make reading garbage more robust

This commit is contained in:
Kovid Goyal 2022-03-15 11:51:46 +05:30
parent 9e317971b4
commit e8437fd435
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -518,9 +518,13 @@ def drain_potential_tty_garbage(p: 'subprocess.Popen[bytes]', data_request: str)
# screen # screen
termios.tcflush(tty.fileno(), termios.TCIFLUSH) termios.tcflush(tty.fileno(), termios.TCIFLUSH)
data = b'' data = b''
start = time.monotonic() give_up_at = time.monotonic() + 1
while time.monotonic() - start < 1 and select([tty], [], [], 0.075)[0]: tty_fd = tty.fileno()
q = os.read(tty.fileno(), io.DEFAULT_BUFFER_SIZE) 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: if not q:
break break
data += q data += q