mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Raise CalledProcessError if openmc.run fails
This commit is contained in:
parent
86df347962
commit
1f816bb919
1 changed files with 9 additions and 5 deletions
|
|
@ -15,18 +15,22 @@ def _run(args, output, cwd):
|
|||
stderr=subprocess.STDOUT, universal_newlines=True)
|
||||
|
||||
# Capture and re-print OpenMC output in real-time
|
||||
lines = []
|
||||
while True:
|
||||
# If OpenMC is finished, break loop
|
||||
line = p.stdout.readline()
|
||||
if not line and p.poll() is not None:
|
||||
break
|
||||
|
||||
lines.append(line)
|
||||
if output:
|
||||
# If user requested output, print to screen
|
||||
print(line, end='')
|
||||
|
||||
# Return the returncode (integer, zero if no problems encountered)
|
||||
return p.returncode
|
||||
# Raise an exception if return status is non-zero
|
||||
if p.returncode != 0:
|
||||
raise subprocess.CalledProcessError(p.returncode, ' '.join(args),
|
||||
''.join(lines))
|
||||
|
||||
|
||||
def plot_geometry(output=True, openmc_exec='openmc', cwd='.'):
|
||||
|
|
@ -42,7 +46,7 @@ def plot_geometry(output=True, openmc_exec='openmc', cwd='.'):
|
|||
Path to working directory to run in
|
||||
|
||||
"""
|
||||
return _run([openmc_exec, '-p'], output, cwd)
|
||||
_run([openmc_exec, '-p'], output, cwd)
|
||||
|
||||
|
||||
def plot_inline(plots, openmc_exec='openmc', cwd='.', convert_exec='convert'):
|
||||
|
|
@ -133,7 +137,7 @@ def calculate_volumes(threads=None, output=True, cwd='.',
|
|||
if mpi_args is not None:
|
||||
args = mpi_args + args
|
||||
|
||||
return _run(args, output, cwd)
|
||||
_run(args, output, cwd)
|
||||
|
||||
|
||||
def run(particles=None, threads=None, geometry_debug=False,
|
||||
|
|
@ -189,4 +193,4 @@ def run(particles=None, threads=None, geometry_debug=False,
|
|||
if mpi_args is not None:
|
||||
args = mpi_args + args
|
||||
|
||||
return _run(args, output, cwd)
|
||||
_run(args, output, cwd)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue