From 4698626c5fb2ec9d84f56c85a25fa5149d47f0f0 Mon Sep 17 00:00:00 2001 From: David Minton Date: Thu, 24 Feb 2022 10:58:57 -0500 Subject: [PATCH] Improved exception handling for the main Fortran code. Python driver should now halt if there was an error encountered in the Fortran code --- python/ctem/ctem/driver.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/python/ctem/ctem/driver.py b/python/ctem/ctem/driver.py index 32c7f4be..401a29b1 100644 --- a/python/ctem/ctem/driver.py +++ b/python/ctem/ctem/driver.py @@ -3,6 +3,7 @@ import subprocess import shutil from ctem import util +import sys class Simulation: """ @@ -178,14 +179,21 @@ def compute_one_interval(self): """ # Create crater population and display CTEM progress on screen print(self.user['ncount'], ' Calling FORTRAN routine') - with subprocess.Popen([os.path.join(self.user['workingdir'], 'CTEM')], + try: + p = subprocess.Popen([os.path.join(self.user['workingdir'], 'CTEM')], stdout=subprocess.PIPE, - universal_newlines=True) as p: - try: - for line in p.stdout: + stderr=subprocess.PIPE, + universal_newlines=True) + for line in p.stdout: + print(line, end='') + res = p.communicate() + if p.returncode != 0: + for line in res[1]: print(line, end='') - except: - print("Error executing main CTEM program") + raise Exception ("CTEM Failure") + except: + print("Error executing main CTEM program") + sys.exit() return