Skip to content

Commit 6b19239

Browse files
committed
CodeQL does not like nested try:
1 parent c1e6750 commit 6b19239

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

cpu_rec.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -780,12 +780,16 @@ def load_training():
780780
log.info("Loading training data from pickled file")
781781
try:
782782
of = open(pickled_data, "rb")
783+
except Exception:
784+
of = None
785+
log.info("Pickle file could not be read")
786+
if of is not None:
783787
try:
784788
p = pickle.load(of)
789+
except Exception:
790+
log.info("Pickled training data could not be loaded")
785791
finally:
786792
of.close()
787-
except Exception:
788-
log.info("Pickled training data could not be loaded")
789793
if p is None:
790794
log.info("No pickled training data, loading from corpus")
791795
t = TrainingData()
@@ -795,16 +799,20 @@ def load_training():
795799
log.info("Saving pickled training data")
796800
try:
797801
of = open(pickled_data, "wb")
802+
except Exception:
803+
of = None
804+
log.info("Pickle file could not be written")
805+
if of is not None:
798806
try:
799807
pickle.dump(p, of)
808+
except OSError:
809+
log.warning("Could not save cached training data")
810+
except TypeError:
811+
# Sometimes fails with "can't pickle instancemethod objects"
812+
log.warning("Can't pickle with this version of python")
813+
os.unlink(pickled_data)
800814
finally:
801815
of.close()
802-
except OSError:
803-
log.warning("Could not save cached training data")
804-
except TypeError:
805-
# Sometimes fails with "can't pickle instancemethod objects"
806-
log.warning("Can't pickle with this version of python")
807-
os.unlink(pickled_data)
808816
return p
809817

810818
training_global_variable = None

0 commit comments

Comments
 (0)