mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Parallel execution when closing VMs.
This commit is contained in:
parent
f2ff933b20
commit
8118d7762f
@ -97,12 +97,18 @@ class BaseManager:
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def unload(self):
|
def unload(self):
|
||||||
|
|
||||||
|
tasks = []
|
||||||
for vm_id in self._vms.keys():
|
for vm_id in self._vms.keys():
|
||||||
try:
|
tasks.append(asyncio.async(self.close_vm(vm_id)))
|
||||||
yield from self.close_vm(vm_id)
|
|
||||||
except Exception as e:
|
if tasks:
|
||||||
log.error("Could not delete VM {}: {}".format(vm_id, e), exc_info=1)
|
done, _ = yield from asyncio.wait(tasks)
|
||||||
continue
|
for future in done:
|
||||||
|
try:
|
||||||
|
future.result()
|
||||||
|
except Exception as e:
|
||||||
|
log.error("Could not close VM {}".format(e), exc_info=1)
|
||||||
|
continue
|
||||||
|
|
||||||
if hasattr(BaseManager, "_instance"):
|
if hasattr(BaseManager, "_instance"):
|
||||||
BaseManager._instance = None
|
BaseManager._instance = None
|
||||||
|
@ -243,11 +243,21 @@ class Project:
|
|||||||
:param cleanup: If True drop the project directory
|
:param cleanup: If True drop the project directory
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
tasks = []
|
||||||
for vm in self._vms:
|
for vm in self._vms:
|
||||||
if asyncio.iscoroutinefunction(vm.close):
|
if asyncio.iscoroutinefunction(vm.close):
|
||||||
yield from vm.close()
|
tasks.append(asyncio.async(vm.close()))
|
||||||
else:
|
else:
|
||||||
vm.close()
|
vm.close()
|
||||||
|
|
||||||
|
if tasks:
|
||||||
|
done, _ = yield from asyncio.wait(tasks)
|
||||||
|
for future in done:
|
||||||
|
try:
|
||||||
|
future.result()
|
||||||
|
except Exception as e:
|
||||||
|
log.error("Could not close VM {}".format(e), exc_info=1)
|
||||||
|
|
||||||
if cleanup and os.path.exists(self.path):
|
if cleanup and os.path.exists(self.path):
|
||||||
try:
|
try:
|
||||||
yield from wait_run_in_executor(shutil.rmtree, self.path)
|
yield from wait_run_in_executor(shutil.rmtree, self.path)
|
||||||
|
Loading…
Reference in New Issue
Block a user