diff --git a/alab_management/task_manager/resource_requester.py b/alab_management/task_manager/resource_requester.py index b79a59e2..a3c1d892 100644 --- a/alab_management/task_manager/resource_requester.py +++ b/alab_management/task_manager/resource_requester.py @@ -240,6 +240,12 @@ def release_resources(self, request_id: ObjectId) -> bool: }, ) + # wait for the request to be released + while (self.get_request(request_id, projection=["status"]))[ + "status" + ] == RequestStatus.NEED_RELEASE.name: + time.sleep(0.5) + return result.modified_count == 1 def release_all_resources(self): @@ -273,6 +279,9 @@ def release_all_resources(self): } }, ) + # wait for all the requests to be released + while any(request["status"] == RequestStatus.NEED_RELEASE.name for request in self.get_requests_by_task_id(self.task_id)): + time.sleep(0.5) def _check_request_status_loop(self): while not self._stop: