Skip to content

Commit 963b717

Browse files
authored
fix: cicd issue due to terminal tool (#3354)
1 parent 6bb17c4 commit 963b717

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

camel/toolkits/terminal_toolkit/terminal_toolkit.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
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
1514
import os
1615
import platform
1716
import 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.

test/toolkits/test_terminal_toolkit.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
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

4245
def 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

4955
def test_shell_exec(terminal_toolkit, temp_dir):

0 commit comments

Comments
 (0)