From af8f9debeaa5045e59cf12c898c7f202cb996397 Mon Sep 17 00:00:00 2001 From: Ovidiu Mircescu Date: Tue, 12 Mar 2019 14:28:55 +0100 Subject: [PATCH] Add "resultAvailable" function. resultAvailable works like getResult but it does not throw exception. getResult throws an exception if the result file does not exist. It is not an error if getResult is called soon after the launching of the job and there was not enough time to create the file. resultAvailable does not throw exceptions. It returns "False" if the result file does not exist. --- src/cpp/Test/StudyRestartTest.cxx | 1 + src/pydefx/pystudy.py | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/cpp/Test/StudyRestartTest.cxx b/src/cpp/Test/StudyRestartTest.cxx index b4bc4f9..7636c65 100644 --- a/src/cpp/Test/StudyRestartTest.cxx +++ b/src/cpp/Test/StudyRestartTest.cxx @@ -74,6 +74,7 @@ void SampleTest::studyTest() CPPUNIT_ASSERT(l.lastError().empty()); // This "wait" will end instantly because of the "ERROR" state. bool ok = restoredJob->wait(); + // ok means that the wait command succeeded. It is not the state of the job. CPPUNIT_ASSERT(ok); double progress = restoredJob->progress(); // We can check the progress in order to know if the job is done, but we diff --git a/src/pydefx/pystudy.py b/src/pydefx/pystudy.py index 48d272c..ce6d15c 100644 --- a/src/pydefx/pystudy.py +++ b/src/pydefx/pystudy.py @@ -196,6 +196,11 @@ class PyStudy: f.write(job_string) def getResult(self): + """ + Try to get the result file and if it was possible the results are loaded in + the sample. + An exception may be thrown if it was not possible to get the file. + """ if self.job_id < 0 : raise Exception("Cannot get the results if the job is not created!") launcher = salome.naming_service.Resolve('/SalomeLauncher') @@ -207,8 +212,23 @@ class PyStudy: self.sampleManager.getResultFileName(), tmp_workdir): self.sampleManager.loadResult(self.sample, tmp_workdir) + else: + raise Exception("Cannot get the result file!") return self.sample + def resultAvailable(self): + """ + Try to get the result and return True in case of success with no exception. + In case of success the results are loaded in the sample. + """ + resultFound = False + try: + self.getResult() + resultFound = True + except: + resultFound = False + return resultFound + def getJobState(self): if self.job_id < 0: return "NOT_CREATED" @@ -221,7 +241,8 @@ class PyStudy: state = self.getJobState() if state == "CREATED" or state == "QUEUED" : return 0.0 - self.getResult(); + if not self.resultAvailable(): + return 0.0 return self.sample.progressRate() def dump(self): -- 2.39.2