Belle II Software development
Local.LocalResult Class Reference
Inheritance diagram for Local.LocalResult:
Result

Public Member Functions

 __init__ (self, job, result)
 
 update_status (self)
 
 ready (self)
 
 get_exit_code_from_file (self)
 

Public Attributes

 result = result
 The underlying result from the backend.
 
 job = job
 Job object for result.
 
 time_to_wait_for_exit_code_file = timedelta(minutes=5)
 After our first attempt to view the exit code file once the job is 'finished', how long should we wait for it to exist before timing out?
 
 exit_code_file_initial_time = None
 Time we started waiting for the exit code file to appear.
 

Protected Member Functions

 _update_result_status (self)
 

Protected Attributes

bool _is_ready = False
 Quicker way to know if it's ready once it has already been found.
 

Detailed Description

Result class to help monitor status of jobs submitted by Local backend.

Definition at line 948 of file backends.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
job,
result )
Pass in the job object and the multiprocessing result to allow the result to do monitoring and perform
post processing of the job.

Definition at line 953 of file backends.py.

953 def __init__(self, job, result):
954 """
955 Pass in the job object and the multiprocessing result to allow the result to do monitoring and perform
956 post processing of the job.
957 """
958 super().__init__(job)
959
960 self.result = result
961

Member Function Documentation

◆ _update_result_status()

_update_result_status ( self)
protected
Update result status

Definition at line 962 of file backends.py.

962 def _update_result_status(self):
963 """
964 Update result status
965 """
966 if self.result.ready() and (self.job.status not in self.job.exit_statuses):
967 return_code = self.result.get()
968 if return_code:
969 self.job.status = "failed"
970 else:
971 self.job.status = "completed"
972

◆ get_exit_code_from_file()

get_exit_code_from_file ( self)
inherited
Read the exit code file to discover the exit status of the job command. Useful fallback if the job is no longer
known to the job database (batch system purged it for example). Since some backends may take time to download
the output files of the job back to the working directory we use a time limit on how long to wait.

Definition at line 908 of file backends.py.

908 def get_exit_code_from_file(self):
909 """
910 Read the exit code file to discover the exit status of the job command. Useful fallback if the job is no longer
911 known to the job database (batch system purged it for example). Since some backends may take time to download
912 the output files of the job back to the working directory we use a time limit on how long to wait.
913 """
914 if not self.exit_code_file_initial_time:
915 self.exit_code_file_initial_time = datetime.now()
916 exit_code_path = Path(self.job.working_dir, Backend.exit_code_file)
917 with open(exit_code_path) as f:
918 exit_code = int(f.read().strip())
919 B2DEBUG(29, f"Exit code from file for {self.job} was {exit_code}")
920 return exit_code
921
922

◆ ready()

ready ( self)
inherited
Returns whether or not this job result is known to be ready. Doesn't actually change the job status. Just changes
the 'readiness' based on the known job status.

Definition at line 887 of file backends.py.

887 def ready(self):
888 """
889 Returns whether or not this job result is known to be ready. Doesn't actually change the job status. Just changes
890 the 'readiness' based on the known job status.
891 """
892 B2DEBUG(29, f"Calling {self.job}.result.ready()")
893 if self._is_ready:
894 return True
895 elif self.job.status in self.job.exit_statuses:
896 self._is_ready = True
897 return True
898 else:
899 return False
900

◆ update_status()

update_status ( self)
Update the job's (or subjobs') status by calling the result object.

Reimplemented from Result.

Definition at line 973 of file backends.py.

973 def update_status(self):
974 """
975 Update the job's (or subjobs') status by calling the result object.
976 """
977 B2DEBUG(29, f"Calling {self.job}.result.update_status()")
978 if self.job.subjobs:
979 for subjob in self.job.subjobs.values():
980 subjob.result._update_result_status()
981 else:
982 self._update_result_status()
983
984 def join(self):

Member Data Documentation

◆ _is_ready

bool _is_ready = False
protectedinherited

Quicker way to know if it's ready once it has already been found.

Saves a lot of calls to batch system commands.

Definition at line 880 of file backends.py.

◆ exit_code_file_initial_time

exit_code_file_initial_time = None
inherited

Time we started waiting for the exit code file to appear.

Definition at line 885 of file backends.py.

◆ job

job = job
inherited

Job object for result.

Definition at line 878 of file backends.py.

◆ result

result = result

The underlying result from the backend.

Definition at line 960 of file backends.py.

◆ time_to_wait_for_exit_code_file

time_to_wait_for_exit_code_file = timedelta(minutes=5)
inherited

After our first attempt to view the exit code file once the job is 'finished', how long should we wait for it to exist before timing out?

Definition at line 883 of file backends.py.


The documentation for this class was generated from the following file: