Skip to content

Commit

Permalink
Make sure read_until_output_matches waits for all data
Browse files Browse the repository at this point in the history
The `read_until_output_matches` function should wait for the match or
until the end of the time. Currently when `read_nonblocking` returns no
output it usually means the pipeline was closed, but it could as well
mean there were no decoded characters.

Let's use the new `_read_nonblocking` function and base our decision on
the number of raw chars read instead of the decoded values to avoid
finishing earlier than our timeout.

Signed-off-by: Haijiao Zhao <[email protected]>
Signed-off-by: Lukáš Doktor <[email protected]>
  • Loading branch information
ldoktor committed May 31, 2021
1 parent 0dcc460 commit 0caac7c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions aexpect/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,10 +866,12 @@ def read_until_output_matches(self, patterns, filter_func=lambda x: x,
if not poll_status:
raise ExpectTimeoutError(patterns, output)
# Read data from child
data = self.read_nonblocking(internal_timeout,
end_time - time.time())
if not data:
read, data = self._read_nonblocking(internal_timeout,
end_time - time.time())
if not read:
break
if not data:
continue
# Print it if necessary
if print_func:
for line in data.splitlines():
Expand Down

0 comments on commit 0caac7c

Please sign in to comment.