Wait for the end of project loading before making new change

Fix #790
This commit is contained in:
Julien Duponchelle committed 2016-11-18 17:35:28 +01:00
1 parent 5ab85e5c9e
commit 40af2a35e0
6 files changed
+56 -44

No files matched your search

+12 -1
View File
@@ -338,13 +338,24 @@ class Controller:
def get_project(self, project_id):
"""
Returns a compute server or raise a 404 error.
Returns a project or raise a 404 error.
"""
try:
return self._projects[project_id]
except KeyError:
raise aiohttp.web.HTTPNotFound(text="Project ID {} doesn't exist".format(project_id))
@asyncio.coroutine
def get_loaded_project(self, project_id):
"""
Returns a project or raise a 404 error.
If project is not finished to load wait for it
"""
project = self.get_project(project_id)
yield from project.wait_loaded()
return project
def remove_project(self, project):
del self._projects[project.id]
+13
View File
@@ -78,6 +78,7 @@ class Project:
self._status = status
self._scene_height = scene_height
self._scene_width = scene_width
self._loading = False
# Disallow overwrite of existing project
if project_id is None and path is not None:
@@ -618,10 +619,12 @@ class Project:
return
self.reset()
self._loading = True
self._status = "opened"
path = self._topology_file()
if not os.path.exists(path):
self._loading = False
return
try:
shutil.copy(path, path + ".backup")
@@ -655,16 +658,26 @@ class Project:
if os.path.exists(path + ".backup"):
shutil.copy(path + ".backup", path)
self._status = "closed"
self._loading = False
raise e
try:
os.remove(path + ".backup")
except OSError:
pass
self._loading = False
# Should we start the nodes when project is open
if self._auto_start:
yield from self.start_all()
@asyncio.coroutine
def wait_loaded(self):
"""
Wait until the project finish loading
"""
while self._loading:
yield from asyncio.sleep(0.5)
@asyncio.coroutine
def duplicate(self, name=None, location=None):
"""