From 1edc1651ee7e59f40245c94f7cfbe1b1b7627a64 Mon Sep 17 00:00:00 2001 From: Sun Junyi Date: Sun, 17 Feb 2013 16:04:51 +0800 Subject: [PATCH] try to fix this issue: https://github.com/fxsjy/jieba/issues/26 --- jieba/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jieba/__init__.py b/jieba/__init__.py index c2d1e0f..d266c4c 100644 --- a/jieba/__init__.py +++ b/jieba/__init__.py @@ -50,7 +50,8 @@ if load_from_cache_fail: FREQ = dict([(k,log(float(v)/total)) for k,v in FREQ.iteritems()]) #normalize min_freq = min(FREQ.itervalues()) print >> sys.stderr, "dumping model to file cache" - marshal.dump((trie,FREQ,total,min_freq),open(cache_file,'wb')) + marshal.dump((trie,FREQ,total,min_freq),open(cache_file+".tmp",'wb')) + os.rename(cache_file+".tmp",cache_file) print >> sys.stderr, "loading model cost ", time.time() - t1, "seconds." print >> sys.stderr, "Trie has been built succesfully."