File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed
camel/toolkits/terminal_toolkit Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change 1111# See the License for the specific language governing permissions and
1212# limitations under the License.
1313# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14- import atexit
1514import os
1615import platform
1716import select
@@ -147,8 +146,6 @@ def __init__(
147146 self .initial_env_path : Optional [str ] = None
148147 self .python_executable = sys .executable
149148
150- atexit .register (self .__del__ )
151-
152149 self .log_dir = os .path .abspath (
153150 session_logs_dir or os .path .join (self .working_dir , "terminal_logs" )
154151 )
@@ -932,13 +929,17 @@ def cleanup(self):
932929 f"during cleanup: { e } "
933930 )
934931
932+ cleanup ._manual_timeout = True # type: ignore[attr-defined]
933+
935934 def __del__ (self ):
936935 r"""Fallback cleanup in destructor."""
937936 try :
938937 self .cleanup ()
939938 except Exception :
940939 pass
941940
941+ __del__ ._manual_timeout = True # type: ignore[attr-defined]
942+
942943 def get_tools (self ) -> List [FunctionTool ]:
943944 r"""Returns a list of FunctionTool objects representing the functions
944945 in the toolkit.
Original file line number Diff line number Diff line change 2121
2222
2323@pytest .fixture
24- def terminal_toolkit (temp_dir ):
25- return TerminalToolkit (working_directory = temp_dir , safe_mode = False )
24+ def terminal_toolkit (temp_dir , request ):
25+ toolkit = TerminalToolkit (working_directory = temp_dir , safe_mode = False )
26+ # Ensure cleanup happens after test completes
27+ request .addfinalizer (toolkit .cleanup )
28+ return toolkit
2629
2730
2831@pytest .fixture
@@ -41,9 +44,12 @@ def test_file(temp_dir):
4144
4245def test_init ():
4346 toolkit = TerminalToolkit ()
44- assert toolkit .timeout == 20.0
45- assert isinstance (toolkit .shell_sessions , dict )
46- assert toolkit .os_type == platform .system ()
47+ try :
48+ assert toolkit .timeout == 20.0
49+ assert isinstance (toolkit .shell_sessions , dict )
50+ assert toolkit .os_type == platform .system ()
51+ finally :
52+ toolkit .cleanup ()
4753
4854
4955def test_shell_exec (terminal_toolkit , temp_dir ):
You can’t perform that action at this time.
0 commit comments