Handles the completion of a process, checks for errors, cleans up stderr_file, and logs messages.
(process, stderr_file, config_path: Path, verbose: bool, gpu_id: Optional[int] = None)
| 144 | |
| 145 | |
| 146 | def handle_process_completion(process, stderr_file, config_path: Path, verbose: bool, gpu_id: Optional[int] = None): |
| 147 | """Handles the completion of a process, checks for errors, cleans up stderr_file, and logs messages.""" |
| 148 | returncode = process.returncode |
| 149 | |
| 150 | # Read and clean up stderr output |
| 151 | if stderr_file is not None: |
| 152 | stderr_file.seek(0) |
| 153 | error_output = stderr_file.read() |
| 154 | stderr_file.close() |
| 155 | os.unlink(stderr_file.name) # Delete the temp file |
| 156 | else: |
| 157 | error_output = "Error output was displayed above." |
| 158 | |
| 159 | # Construct job identifier |
| 160 | if gpu_id is not None: |
| 161 | job_identifier = f"Job on GPU {gpu_id} for {config_path.name}" |
| 162 | else: |
| 163 | job_identifier = f"Job for {config_path.name}" |
| 164 | |
| 165 | if returncode != 0: |
| 166 | # The process exited with an error |
| 167 | if verbose: |
| 168 | print(f"{job_identifier} failed with return code {returncode}") |
| 169 | print("Error Output:") |
| 170 | print(error_output) |
| 171 | else: |
| 172 | console.print(f"[red]{job_identifier} failed with return code {returncode}[/red]") |
| 173 | console.print(f"[red]Error Output:[/red]\n{error_output}") |
| 174 | else: |
| 175 | # The process completed successfully |
| 176 | if verbose: |
| 177 | print(f"{job_identifier} has finished successfully.") |
| 178 | else: |
| 179 | console.log(f"{job_identifier} has finished successfully.") |
| 180 | |
| 181 | |
| 182 | def run_job( |
no outgoing calls
no test coverage detected