소스 검색

some minor changes in the calling of the PipelineCache

Dimitri Korsch 3 년 전
부모
커밋
34b429f87b

+ 2 - 4
pycs/frontend/endpoints/labels/EditLabelName.py

@@ -31,10 +31,8 @@ class EditLabelName(View):
         if label is None:
             abort(404)
 
-        # start transaction
-        with self.db:
-            # change name
-            label.set_name(data['name'])
+        # change name
+        label.set_name(data['name'])
 
         # send notification
         NotificationManager.edited("label", label.id, Label)

+ 2 - 3
pycs/frontend/endpoints/pipelines/FitModel.py

@@ -54,15 +54,14 @@ class FitModel(View):
         pipeline = None
 
         project = Project.query.get(project_id)
-        model = project.model
         storage = MediaStorage(project_id)
 
         # load pipeline
         try:
-            pipeline = pipelines.load_from_root_folder(project, model.root_folder)
+            pipeline = pipelines.load_from_root_folder(project)
             yield from pipeline.fit(storage)
         except TypeError:
             pass
         finally:
             if pipeline is not None:
-                pipelines.free_instance(model.root_folder)
+                pipelines.free_instance(project)

+ 2 - 3
pycs/frontend/endpoints/pipelines/PredictModel.py

@@ -74,7 +74,6 @@ class PredictModel(View):
 
         try:
             project = Project.query.get(project_id)
-            model = project.model
             storage = MediaStorage(project_id, notifications)
 
             # create a list of MediaFile
@@ -94,7 +93,7 @@ class PredictModel(View):
 
             # load pipeline
             try:
-                pipeline = pipelines.load_from_root_folder(project, model.root_folder)
+                pipeline = pipelines.load_from_root_folder(project)
 
                 # iterate over files
                 index = 0
@@ -118,7 +117,7 @@ class PredictModel(View):
 
             finally:
                 if pipeline is not None:
-                    pipelines.free_instance(model.root_folder)
+                    pipelines.free_instance(project)
 
         except Exception as e:
             import traceback

+ 6 - 2
pycs/util/PipelineCache.py

@@ -51,7 +51,7 @@ class PipelineCache(GreenWorker):
         self.__lock = Lock()
 
 
-    def load_from_root_folder(self, project: Project, root_folder: str, no_cache: bool = False) -> Pipeline:
+    def load_from_root_folder(self, project: Project, no_cache: bool = False) -> Pipeline:
         """
         load configuration.json and create an instance from the included code object
 
@@ -59,6 +59,8 @@ class PipelineCache(GreenWorker):
         :param root_folder: path to model root folder
         :return: Pipeline instance
         """
+        root_folder = project.model.root_folder
+
         # check if instance is cached
         with self.__lock:
             if root_folder in self.__pipelines:
@@ -85,7 +87,7 @@ class PipelineCache(GreenWorker):
         # return
         return pipeline
 
-    def free_instance(self, root_folder: str):
+    def free_instance(self, project: Project):
         """
         Change an instance's status to unused and start the timer to call it's `close` function
         after `CLOSE_TIMER` seconds. The next call to `load_from_root_folder` in this interval
@@ -93,6 +95,8 @@ class PipelineCache(GreenWorker):
 
         :param root_folder: path to model root folder
         """
+        root_folder = project.model.root_folder
+
         with self.__lock:
             if root_folder in self.__pipelines:
                 # reset "last used" to now