我在使用pickle加载特定文件时遇到了一个奇怪的问题。
我在OSX上使用PyPy。这些文件最初使用相同的配置生成,显然使用pickle.dump()。 下面的代码遍历pickle文件并尝试读取它们。大多数文件已成功加载,但有些文件(截至目前为止发现的两个文件)没有成功加载。 每个文件大约64MB,我有足够的RAM。可能是错误的原因是什么?
poolFiles = get_all_files('../test','.pool')
counter = Counter()
for p in poolFiles:
print p
with open(p,'rb') as f:
bots = pickle.load(f)
for botID, genome in bots.iteritems():
counter.update({botID})
../test/best_performers.pool
../test/best_performers_01.pool
../test/best_performers_02.pool
../test/best_performers_03.pool
../test/best_performers_04.pool
../test/best_performers_05.pool
../test/best_performers_06.pool
../test/best_performers_07.pool
---------------------------------------------------------------------------
EOFError Traceback (most recent call last)
<ipython-input-4-22bb8d4b58db> in <module>()
5 print p
6 with open(p,'rb') as f:
----> 7 bots = pickle.load(f)
8 for botID, genome in bots.iteritems():
9 counter.update({botID})
/usr/local/Cellar/pypy/5.3.0/libexec/lib-python/2.7/pickle.pyc in load(file)
1425
1426 def load(file):
-> 1427 return Unpickler(file).load()
1428
1429 def loads(str):
/usr/local/Cellar/pypy/5.3.0/libexec/lib-python/2.7/pickle.pyc in load(self)
899 while 1:
900 key = read(1)
--> 901 dispatch[key](self)
902 except _Stop, stopinst:
903 return stopinst.value
/usr/local/Cellar/pypy/5.3.0/libexec/lib-python/2.7/pickle.pyc in load_eof(self)
921
922 def load_eof(self):
--> 923 raise EOFError
924 dispatch[''] = load_eof
925
EOFError: