Fix case when the vms are deleted manually but still be attempted to be recognized by .vms info

This commit is contained in:
Timothyxxx
2024-06-02 01:22:15 +08:00
parent cfc5500a8a
commit 5b3cf1640f

View File

@@ -12,7 +12,7 @@ import psutil
import requests
from tqdm import tqdm
__version__ = "0.1.12"
__version__ = "0.1.15"
MAX_RETRY_TIMES = 10
UBUNTU_ARM_URL = "https://huggingface.co/datasets/xlangai/ubuntu_arm/resolve/main/Ubuntu.zip"
@@ -78,10 +78,16 @@ class VirtualMachineManager:
active_pids = {p.pid for p in psutil.process_iter()}
new_lines = []
vm_paths = []
with open(self.registry_path, 'r') as file:
lines = file.readlines()
for line in lines:
vm_path, pid_str = line.strip().split('|')
if not os.path.exists(vm_path):
print(f"VM {vm_path} not found, releasing it.")
new_lines.append(f'{vm_path}|free\n')
continue
vm_paths.append(vm_path)
if pid_str == "free":
new_lines.append(line)