Skip to content

Commit 4b74402

Browse files
Merge pull request #240 from KernelTuner/reduce_complexity_read_cache
improve code quality of cache file related functions
2 parents 5465a09 + cf5866c commit 4b74402

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

kernel_tuner/util.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,8 +1167,9 @@ def process_cache(cache, kernel_options, tuning_options, runner):
11671167
tuning_options.cache = cached_data["cache"]
11681168

11691169

1170-
def read_cache(cache, open_cache=True):
1171-
"""Read the cachefile into a dictionary, if open_cache=True prepare the cachefile for appending."""
1170+
def correct_open_cache(cache, open_cache=True):
1171+
""" if cache file was not properly closed, pretend it was properly closed """
1172+
11721173
with open(cache, "r") as cachefile:
11731174
filestr = cachefile.read().strip()
11741175

@@ -1185,6 +1186,13 @@ def read_cache(cache, open_cache=True):
11851186
with open(cache, "w") as cachefile:
11861187
cachefile.write(filestr[:-3] + ",")
11871188

1189+
return filestr
1190+
1191+
def read_cache(cache, open_cache=True):
1192+
"""Read the cachefile into a dictionary, if open_cache=True prepare the cachefile for appending."""
1193+
1194+
filestr = correct_open_cache(cache, open_cache)
1195+
11881196
error_configs = {
11891197
"InvalidConfig": InvalidConfig(),
11901198
"CompilationFailedConfig": CompilationFailedConfig(),

0 commit comments

Comments
 (0)