Skip to content

Commit

Permalink
fix: Raise error when aexpect_helper doesn't work properly
Browse files Browse the repository at this point in the history
When aexpect_helper does not work properly, the process will hang
without any log information. This fix adds a timeout and checks the
process status and raises an error if the process terminates
prematurely.

Signed-off-by: Yihuang Yu <[email protected]>
  • Loading branch information
PaulYuuu committed Aug 1, 2024
1 parent 4e5ac96 commit 9414aec
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions aexpect/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,19 @@ def __init__(self, command=None, a_id=None, auto_close=False, echo=False,
sub.stdin.write(f"{command}\n".encode(self.encoding))
sub.stdin.flush()
# Wait for the server to complete its initialization
while (f"Server {self.a_id} ready" not in
sub.stdout.readline().decode(self.encoding, "ignore")):
pass
full_output = ""
pattern = f"Server {self.a_id} ready"
end_time = time.time() + 60
while time.time() < end_time:
output = sub.stdout.readline().decode(self.encoding, "ignore")
if pattern in output:
break
full_output += output
sub_status = sub.poll()
if sub_status is not None:
raise ExpectProcessTerminatedError(pattern, sub_status, full_output)
else:
raise ExpectTimeoutError(pattern, full_output)

# Open the reading pipes
if is_file_locked(self.lock_server_running_filename):
Expand Down

0 comments on commit 9414aec

Please sign in to comment.