Execute the script. The script is executed directly and is _not_ submitted to a job scheduler. The script file is written before being executed. Args: overwrite (bool): Whether to overwrite script file if it already exists (default: false
(self, overwrite=False)
| 138 | os.chmod(self.script_file, 0o755) |
| 139 | |
| 140 | def run(self, overwrite=False): |
| 141 | """Execute the script. |
| 142 | |
| 143 | The script is executed directly and is _not_ submitted to a |
| 144 | job scheduler. The script file is written before being |
| 145 | executed. |
| 146 | |
| 147 | Args: |
| 148 | overwrite (bool): Whether to overwrite script file if it |
| 149 | already exists (default: false). |
| 150 | |
| 151 | Returns: |
| 152 | int: Exit status from executing script. |
| 153 | |
| 154 | """ |
| 155 | |
| 156 | # Construct script file |
| 157 | self.write(overwrite=overwrite) |
| 158 | |
| 159 | # Run script and pipe output to log files |
| 160 | run_proc = subprocess.Popen(self.script_file, |
| 161 | stdout=subprocess.PIPE, |
| 162 | stderr=subprocess.PIPE, |
| 163 | cwd=self.work_dir) |
| 164 | out_proc = subprocess.Popen(['tee', self.out_log_file], |
| 165 | stdin=run_proc.stdout, |
| 166 | cwd=self.work_dir) |
| 167 | err_proc = subprocess.Popen(['tee', self.err_log_file], |
| 168 | stdin=run_proc.stderr, |
| 169 | cwd=self.work_dir) |
| 170 | run_proc.stdout.close() |
| 171 | run_proc.stderr.close() |
| 172 | run_proc.wait() |
| 173 | out_proc.wait() |
| 174 | err_proc.wait() |
| 175 | return run_proc.returncode |
| 176 | |
| 177 | def submit(self, overwrite=False): |
| 178 | """Submit batch job to job scheduler. |