1
我只是想從一些7500個文件中計算出字數,並用某些條件來計算字數。該程序是這樣的。爲什麼我在使用mincemeat時在map-reduce中不斷收到此錯誤?
import glob
import mincemeat
text_files = glob.glob('../fldr/2/*')
def file_contents(file_name):
f = open(file_name)
try:
return f.read()
finally:
f.close()
source = dict((file_name, file_contents(file_name))
for file_name in text_files)
def mapfn(key, value):
for line in value.splitlines():
list2 = [ ]
for temp in line.split("::::"):
list2.append(temp)
if (list2[0] == '5'):
for review in list2[1].split():
yield [review.lower(),1]
def reducefn(key, value):
return key, len(value)
s = mincemeat.Server()
s.datasource = source
s.mapfn = mapfn
s.reducefn = reducefn
results = s.run_server(password="wola")
print results
我得到的同時運行這個程序是
error: uncaptured python exception, closing channel <__main__.Client connected at 0x250f990>
(<type 'exceptions.IndexError'>:list index out of range
[C:\Python27\lib\asyncore.py|read|83]
[C:\Python27\lib\asyncore.py|handle_read_event|444]
[C:\Python27\lib\asynchat.py|handle_read|140]
[mincemeat.py|found_terminator|96]
[mincemeat.py|process_command|194]
[mincemeat.py|call_mapfn|170]
[projminc2.py|mapfn|21])
無論是否拋出異常,您的代碼是否關閉?你可以把這個關閉調用放入catch(或者Python中的任何東西)嗎? –
不起作用..我只是試圖把它扔在一個嘗試異常塊..但同樣的錯誤再次彈出... – amian
看看你的索引。錯誤說你有索引問題。 –