add longer retries

This commit is contained in:
Jing Hua
2023-12-03 17:24:44 +08:00
parent 58e9807a70
commit b10908b4fa

View File

@@ -53,19 +53,22 @@ class DesktopEnv(gym.Env):
else: else:
print("Starting VM...") print("Starting VM...")
_execute_command(["vmrun", "-T", "ws", "start", self.path_to_vm]) _execute_command(["vmrun", "-T", "ws", "start", self.path_to_vm])
time.sleep(10) time.sleep(3)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print(f"Error executing command: {e.output.decode().strip()}") print(f"Error executing command: {e.output.decode().strip()}")
def _get_vm_ip(self): def _get_vm_ip(self):
max_retries = 3 max_retries = 10
print("Getting IP Address...")
for _ in range(max_retries): for _ in range(max_retries):
try: try:
output = _execute_command(["vmrun", "-T", "ws", "getGuestIPAddress", self.path_to_vm]) output = _execute_command(["vmrun", "-T", "ws", "getGuestIPAddress", self.path_to_vm]).strip()
return output.strip() print(f"IP address: {output}")
return output
except: except:
time.sleep(2) time.sleep(5)
print("Retrying...") print("Retrying...")
raise Exception("Failed to get VM IP address!")
def _save_state(self): def _save_state(self):
_execute_command(["vmrun", "-T", "ws" "snapshot", self.path_to_vm, self.snapshot_path]) _execute_command(["vmrun", "-T", "ws" "snapshot", self.path_to_vm, self.snapshot_path])