Verified Commit 84e6788e authored by Karel Koci's avatar Karel Koci 🤘
Browse files

nsfarm/cli: fix function pexpect_flush

It turns out that nonblocking doesn't mean nonblocking in all cases. In
this case when there was no input the read was blocking.
The timeout set to zero solves this.
parent b2a9f818
......@@ -82,7 +82,7 @@ class Board(abc.ABC):
# Wait for bootup
self._pexpect.expect_exact(["Router Turris successfully started.", ], timeout=120)
# Note Shell sends new line which opens terminal for it
shell = cli.Shell(self._pexpect, flush=False) # TODO why this flush timeouts?
shell = cli.Shell(self._pexpect)
shell.run("sysctl -w kernel.printk='0 4 1 7'") # disable kernel print to not confuse console flow
return shell
......
......@@ -18,6 +18,7 @@ import select
import socket
import threading
import typing
import pexpect
_FLUSH_BUFFLEN = 2048
......@@ -25,9 +26,14 @@ _FLUSH_BUFFLEN = 2048
def pexpect_flush(pexpect_handle):
"""Flush all input on pexpect. This effectively reads everything.
"""
# TODO fix: this timeouts if there is nothing to flush
while len(pexpect_handle.read_nonblocking(_FLUSH_BUFFLEN)) == _FLUSH_BUFFLEN:
pass
# The read_nonblocking blocks when there is not at least one byte available for read (yeah you are reading it right
# the nonblocking read is blocking). The solution here is to use timeout with zero value. This raises timeout
# exception immediately once there is no input available.
while True:
try:
pexpect_handle.read_nonblocking(io.DEFAULT_BUFFER_SIZE, 0)
except pexpect.TIMEOUT:
return
def run_exit_code_zero(exit_code):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment