From e480480e33d1a0294fc96631f87b94ce51b5d9c5 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 967310f..8e790c8 100644 --- a/aexpect/client.py +++ b/aexpect/client.py @@ -532,6 +532,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) @@ -552,7 +553,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()