Skip to content

Commit 3761c9d

Browse files
Add try except, where esmf files are not ready, preventing errors but still leaving a warning message
1 parent db09a87 commit 3761c9d

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

ESMF_profiling/esmfFileParser.py

+20-14
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
# ===========================================================================
4141
import os
4242
import re
43+
import warnings
4344
from esmfRegion import ESMFRegion
4445
import time
4546

@@ -76,22 +77,27 @@ def collect_runtime_tot(
7677

7778
def _list_esmf_files(dir_path, profile_prefix, esmf_summary, summary_profile):
7879
"""Lists ESMF files based on a prefix."""
79-
files = os.listdir(dir_path)
80-
if not esmf_summary:
81-
# ESMF_Profile.xxxx
82-
matching_files = [
83-
file
84-
for file in files
85-
if file.startswith(profile_prefix) and file != summary_profile
80+
try:
81+
files = os.listdir(dir_path)
82+
if not esmf_summary:
83+
# ESMF_Profile.xxxx
84+
matching_files = [
85+
file
86+
for file in files
87+
if file.startswith(profile_prefix) and file != summary_profile
88+
]
89+
matching_files.sort(key=lambda x: int(x[len(profile_prefix) :]))
90+
else:
91+
# ESMF_Profile.summary
92+
matching_files = [summary_profile]
93+
94+
matching_files_path = [
95+
os.path.join(dir_path, matching_file) for matching_file in matching_files
8696
]
87-
matching_files.sort(key=lambda x: int(x[len(profile_prefix) :]))
88-
else:
89-
# ESMF_Profile.summary
90-
matching_files = [summary_profile]
97+
except FileNotFoundError:
98+
warnings.warn(f"Directory {dir_path} does not exist! Skipping!")
99+
matching_files_path = []
91100

92-
matching_files_path = [
93-
os.path.join(dir_path, matching_file) for matching_file in matching_files
94-
]
95101
return matching_files_path
96102

97103

0 commit comments

Comments
 (0)