Skip to content

Commit

Permalink
GYRE threads and processes terminated incase of exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
gautam-404 committed Feb 15, 2024
1 parent dc1c600 commit d84858d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions mesaport/ProjectOps/project_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ def runGyre(self, gyre_in, files='all', wdir=None, data_format="GYRE", silent=Tr
elif target == 'secondary':
LOGS_dir = os.path.join(self.work_dir, "LOGS2") if wdir is None else wdir
else:
raise ValueError('''Invalid input for argument 'star'.
Please use 'primary' or 'secondary''')
raise ValueError("""Invalid input for argument 'star'.
Please use primary or secondary""")
else:
LOGS_dir = os.path.join(self.work_dir, "LOGS") if wdir is None else wdir

Expand Down Expand Up @@ -395,16 +395,23 @@ def runGyre(self, gyre_in, files='all', wdir=None, data_format="GYRE", silent=Tr
n_processes = (n_cores//int(os.environ['OMP_NUM_THREADS']))
with Pool(n_processes) as pool:
gyre_in = os.path.abspath(gyre_in)
for _ in pool.istarmap(ops_helper.run_subprocess, zip(*args)):
progressbar.advance(task)
try:
for _ in pool.istarmap(ops_helper.run_subprocess, zip(*args)):
progressbar.advance(task)
except Exception as e:
print(e)
pool.terminate()
else:
try:
from concurrent.futures import ThreadPoolExecutor
n_processes = (n_cores//int(os.environ['OMP_NUM_THREADS']))
with ThreadPoolExecutor(max_workers=n_processes) as executor:
gyre_in = os.path.abspath(gyre_in)
executor.map(ops_helper.run_subprocess, *args)

try:
executor.map(ops_helper.run_subprocess, *args)
except Exception as e:
print(e)
executor.shutdown(wait=False)
except Exception as e:
filenames = glob.glob(os.path.join(LOGS_dir, f"gyreprofile*.log"))
with open(runlog, 'a+') as outfile:
Expand Down

0 comments on commit d84858d

Please sign in to comment.