Added exception checking for pickle format conversion

This commit is contained in:
Yacine Filali
2017-05-24 10:26:33 -07:00
parent 15e61768f2
commit 4364bebf38
2 changed files with 7 additions and 2 deletions

View File

@@ -110,7 +110,7 @@ def extract_signature(msg_body):
return (stripped_body.strip(),
signature.strip())
except Exception as e:
except Exception:
log.exception('ERROR extracting signature')
return (msg_body, None)

View File

@@ -35,11 +35,16 @@ def load(saved_classifier_filename, train_data_filename):
try:
return joblib.load(saved_classifier_filename)
except ValueError:
# load python 2 pickle format with python 3, and save it permissions allowing
import sys
kwargs = {}
if sys.version_info > (3, 0):
kwargs["encoding"] = "latin1"
loaded = pickle.load(open(saved_classifier_filename, 'rb'), **kwargs)
try:
joblib.dump(loaded, saved_classifier_filename, compress=True)
except Exception:
pass
return joblib.load(saved_classifier_filename)