From 8434e68b6304f84c2e87a9be1f56783e907e5e27 Mon Sep 17 00:00:00 2001 From: David Minton Date: Mon, 21 Nov 2022 11:09:26 -0500 Subject: [PATCH] Re-enabled exception catching and started the process of adding curses so I can make a more useful output display --- python/swiftest/swiftest/simulation_class.py | 46 ++++++++++---------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 1996b1625..b2620d7b1 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -18,7 +18,7 @@ import json import os from pathlib import Path -import sys +import curses import datetime import xarray as xr import numpy as np @@ -397,27 +397,29 @@ def run(self,**kwargs): f.write(f"{str(self.driver_executable)} {self.integrator} {str(self.param_file)} compact\n") cmd = f"{env['SHELL']} -l {driver_script}" - oldline = None - with subprocess.Popen(shlex.split(cmd), - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - env=env, - universal_newlines=True) as p: - for line in p.stdout: - if '[' in line: - print(line.replace('\n','\r'), end='') - elif "Normal termination" in line: - print(line.replace("Normal termination","\n\nNormal termination"),end='') - else: - print(line, end='') - res = p.communicate() - if p.returncode != 0: - for line in res[1]: - print(line, end='') - raise Exception ("Failure in swiftest_driver") - #except: - # warnings.warn(f"Error executing main swiftest_driver program",stacklevel=2) - # return + + stdscr = curses.initscr() + try: + with subprocess.Popen(shlex.split(cmd), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=env, + universal_newlines=True) as p: + for line in p.stdout: + if '[' in line: + print(line.replace('\n','\r'), end='') + elif "Normal termination" in line: + print(line.replace("Normal termination","\n\nNormal termination"),end='') + else: + print(line, end='') + res = p.communicate() + if p.returncode != 0: + for line in res[1]: + print(line, end='') + warnings.warn("Failure in swiftest_driver", stacklevel=2) + except: + warnings.warn(f"Error executing main swiftest_driver program",stacklevel=2) + return # Read in new data self.bin2xr()