close cache file to avoid warning message.

This commit is contained in:
jagt 2014-04-24 00:35:09 +08:00
parent 1f144ebf55
commit 7f3513edb7

View File

@ -84,7 +84,8 @@ def initialize(*args):
if os.path.exists(cache_file) and os.path.getmtime(cache_file)>os.path.getmtime(abs_path):
logger.debug("loading model from cache %s" % cache_file)
try:
trie,FREQ,total,min_freq = marshal.load(open(cache_file,'rb'))
with open(cache_file, 'rb') as cf:
trie,FREQ,total,min_freq = marshal.load(cf)
load_from_cache_fail = False
except:
load_from_cache_fail = True