Skip to content

Commit

Permalink
CodeQL does not like nested try:
Browse files Browse the repository at this point in the history
  • Loading branch information
LRGH committed Mar 10, 2024
1 parent c1e6750 commit 6b19239
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions cpu_rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,12 +780,16 @@ def load_training():
log.info("Loading training data from pickled file")
try:
of = open(pickled_data, "rb")
except Exception:
of = None
log.info("Pickle file could not be read")
if of is not None:
try:
p = pickle.load(of)
except Exception:
log.info("Pickled training data could not be loaded")
finally:
of.close()
except Exception:
log.info("Pickled training data could not be loaded")
if p is None:
log.info("No pickled training data, loading from corpus")
t = TrainingData()
Expand All @@ -795,16 +799,20 @@ def load_training():
log.info("Saving pickled training data")
try:
of = open(pickled_data, "wb")
except Exception:
of = None
log.info("Pickle file could not be written")
if of is not None:
try:
pickle.dump(p, of)
except OSError:
log.warning("Could not save cached training data")
except TypeError:
# Sometimes fails with "can't pickle instancemethod objects"
log.warning("Can't pickle with this version of python")
os.unlink(pickled_data)
finally:
of.close()
except OSError:
log.warning("Could not save cached training data")
except TypeError:
# Sometimes fails with "can't pickle instancemethod objects"
log.warning("Can't pickle with this version of python")
os.unlink(pickled_data)
return p

training_global_variable = None
Expand Down

0 comments on commit 6b19239

Please sign in to comment.