From 4699c57aeaec6d65cc6b9e445e3f3f6d4189f7a6 Mon Sep 17 00:00:00 2001 From: Yihuang Yu Date: Thu, 1 Aug 2024 16:42:00 +0800 Subject: [PATCH] fix: Ensure self.tail_thread to be set before add_close_hook The self.tail_thread attrbuite must to be set before adding the Tail._join_thread to prevent unable to use it on cleanup, otherwise sometimes will raise AttributeError. Signed-off-by: Yihuang Yu --- aexpect/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aexpect/client.py b/aexpect/client.py index 8c89a38..522ece1 100644 --- a/aexpect/client.py +++ b/aexpect/client.py @@ -554,6 +554,7 @@ def __init__(self, command=None, a_id=None, auto_close=False, echo=False, :param encoding: Override text encoding (by default: autodetect by locale.getpreferredencoding()) """ + self.tail_thread = None # Add a reader and a close hook self._add_reader("tail") self._add_close_hook(Tail._join_thread) @@ -574,7 +575,6 @@ def __init__(self, command=None, a_id=None, auto_close=False, echo=False, self.output_prefix = output_prefix # Start the thread in the background - self.tail_thread = None if self.is_alive(): if termination_func or output_func: self._start_thread()