Implement graceful exit cleanup for terminal tool

- Added a new `_atexit_cleanup` function to handle cleanup of active environments and stop the cleanup thread upon program exit.
- Enhanced logging to inform users about the number of remaining sandboxes being shut down during cleanup.
This commit is contained in:
teknium
2026-02-10 22:53:44 +00:00
parent ba3fea24f1
commit 999a28062d

View File

@@ -1365,7 +1365,15 @@ def cleanup_vm(task_id: str):
print(f"[Terminal Cleanup] Error cleaning up environment for task {task_id}: {e}")
atexit.register(_stop_cleanup_thread)
def _atexit_cleanup():
"""Stop cleanup thread and shut down all remaining sandboxes on exit."""
_stop_cleanup_thread()
if _active_environments:
count = len(_active_environments)
print(f"\n[Terminal Cleanup] Shutting down {count} remaining sandbox(es)...")
cleanup_all_environments()
atexit.register(_atexit_cleanup)
def terminal_tool(