2012-06-20 91 views
2

我在Python中使用minidom解析器得到了一個MemoryError。 我讀8000個的小文件(50歲以下最KB),我已經後2500讀數得到這個錯誤...`MemoryError在Python中使用minidom

Traceback (most recent call last): 

File "C:\eclipse\plugins\org.python.pydev.debug_2.4.0.2012020116\pysrc\pydevd.py", line 1307, in <module> 
    debugger.run(setup['file'], None, None) 
    File "C:\eclipse\plugins\org.python.pydev.debug_2.4.0.2012020116\pysrc\pydevd.py", line 1060, in run 
    pydev_imports.execfile(file, globals, locals) #execute the script 
    File "C:\Users\calculator_2012.py", line 81, in <module> 
    file_content, economicFlow, elementaryFlow = XML_reader(spoldFile) 
    File "C:\Users\XML_reader.py", line 10, in XML_reader 
    xmltree = parse(spold_filename) 
    File "C:\Python27\lib\xml\dom\minidom.py", line 1914, in parse 
    return expatbuilder.parse(file) 
    File "C:\Python27\lib\xml\dom\expatbuilder.py", line 924, in parse 
    result = builder.parseFile(fp) 
    File "C:\Python27\lib\xml\dom\expatbuilder.py", line 207, in parseFile 
    parser.Parse(buffer, 0) 
    File "C:\Python27\lib\xml\dom\expatbuilder.py", line 294, in character_data_handler_cdata 
    _append_child(self.curNode, node) 
    File "C:\Python27\lib\xml\dom\minidom.py", line 274, in _append_child 
    def _append_child(self, node): 
    File "C:\eclipse\plugins\org.python.pydev.debug_2.4.0.2012020116\pysrc\pydevd.py", line 942, in trace_dispatch 
    traceback.print_exc() 
    File "C:\Python27\lib\traceback.py", line 232, in print_exc 
    print_exception(etype, value, tb, limit, file) 
MemoryError 

是否有任何人誰可以提出一個「內存泄漏免費」解析器?

+3

嘗試'xml.etree.cElementTree'。如果你在Eclipse之外運行你的腳本,你會得到MemoryError嗎? – jfs

回答

0

那麼,回溯表明你正在PyDev調試器中運行,所以,你有沒有嘗試過在Eclipse中運行它沒有調試器?

1

libxml2的是速度更快,沒有memoryleak,但它太Ç希望得到什麼好處,有可怕的文檔

LXML超過libxm2層和etree模塊,這樣是Python的方式與libxml2的表現

http://lxml.de/

編輯:錯別字

3

我也建議內建cElementTree。 Minidom有很多問題:/

否則lxml也相當不錯,具有更多功能。

2

我看來minidom可以佔用大量的內存。

我試圖解析一個56MB的文件,它需要8G內存來讀取它。

你做數學..