Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improved exception handling for the main Fortran code. Python driver should now halt if there was an error encountered in the Fortran code
  • Loading branch information
daminton committed Feb 24, 2022
1 parent 2b9e3a6 commit 4698626
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions python/ctem/ctem/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
import shutil
from ctem import util
import sys

class Simulation:
"""
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 4698626

Please sign in to comment.