Fix thread lock in AWS, VirtualBox, and VMware (#49)

* Initailize aws support

* Add README for the VM server

* Refactor OSWorld for supporting more cloud services.

* Initialize vmware and aws implementation v1, waiting for verification

* Initlize files for azure, gcp and virtualbox support

* Debug on the VMware provider

* Fix on aws interface mapping

* Fix instance type

* Refactor

* Clean

* Add Azure provider

* hk region; debug

* Fix lock

* Remove print

* Remove key_name requirements when allocating aws vm

* Clean README

* Fix reset

* Fix bugs

* Add VirtualBox and Azure providers

* Add VirtualBox OVF link

* Raise exception on macOS host

* Init RAEDME for VBox

* Update VirtualBox VM download link

* Update requirements and setup.py; Improve robustness on Windows

* Fix network adapter

* Go through on Windows machine

* Add default adapter option

* Fix minor error

* Change resolution before creating snapshot

* Fix small error

* Change default provider option

* Fix thread lock

* Refactor for more smooth VMware support

---------

Co-authored-by: Timothyxxx <384084775@qq.com>
Co-authored-by: XinyuanWangCS <xywang626@gmail.com>
Co-authored-by: Tianbao Xie <47296835+Timothyxxx@users.noreply.github.com>
This commit is contained in:
HappySix
2024-06-20 23:54:50 +08:00
committed by GitHub
parent 16c3defe20
commit df70b11cf6
5 changed files with 171 additions and 63 deletions

View File

@@ -3,7 +3,6 @@ from filelock import FileLock
import boto3
import psutil
import logging
from multiprocessing import Manager
from desktop_env.providers.base import VMManager
@@ -67,9 +66,6 @@ def _allocate_vm(region=DEFAULT_REGION):
class AWSVMManager(VMManager):
manager = Manager()
check_and_clean_event = manager.Event()
def __init__(self, registry_path=REGISTRY_PATH):
self.registry_path = registry_path
self.lock = FileLock(".aws_lck", timeout=60)
@@ -240,24 +236,27 @@ class AWSVMManager(VMManager):
def get_vm_path(self, region=DEFAULT_REGION):
with self.lock:
if not AWSVMManager.check_and_clean_event.is_set():
AWSVMManager.check_and_clean_event.set()
if not AWSVMManager.checked_and_cleaned:
AWSVMManager.checked_and_cleaned = True
self._check_and_clean()
allocation_needed = False
with self.lock:
free_vms_paths = self._list_free_vms(region)
if len(free_vms_paths) == 0:
# No free virtual machine available, generate a new one
if len(free_vms_paths) == 0:
# No free virtual machine available, generate a new one
allocation_needed = True
else:
# Choose the first free virtual machine
chosen_vm_path = free_vms_paths[0][0]
self._occupy_vm(chosen_vm_path, os.getpid(), region)
return chosen_vm_path
if allocation_needed:
logger.info("No free virtual machine available. Generating a new one, which would take a while...☕")
new_vm_path = _allocate_vm(region)
with self.lock:
self._add_vm(new_vm_path, region)
self._occupy_vm(new_vm_path, os.getpid(), region)
return new_vm_path
else:
# Choose the first free virtual machine
chosen_vm_path = free_vms_paths[0][0]
with self.lock:
self._occupy_vm(chosen_vm_path, os.getpid(), region)
return chosen_vm_path