closing sax

Richard West rwest at opti.cgi.net
Thu Oct 25 17:56:15 EDT 2001


I'm using Python 2.1.1's XML support in a long running process and I
seem to be getting a memory leak.  According to the documentation on
xml.sax.xmlreader. IncrementalParser you can call .close() on the
object after parsing is done in order to "clean up any resources
during parsing".  However, when I do that, I get a traceback which I
don't understand.


import string
import xml.sax
import StringIO

test_xml = string.join([
    '<?xml version="1.0"?>',
    '<test>',
    '<user>test</user>',
    '<pass>password</pass>',
    '<tests>',
    '    <atest>123</atest>',
    '    <atest>456</atest>',
    '</tests>',
    '</test>',
    ],'\n')
test = StringIO.StringIO(test_xml)

p = xml.sax.make_parser()
p.setContentHandler(xml.sax.handler.ContentHandler())
p.parse(test)
p.close()



Traceback (most recent call last):
  File "test4.py", line 22, in ?
    p.close()
  File "/usr/local/lib/python2.1/xml/sax/expatreader.py", line 98, in
close
    self.feed("", isFinal = 1)
  File "/usr/local/lib/python2.1/xml/sax/expatreader.py", line 92, in
feed
    self._err_handler.fatalError(exc)
  File "/usr/local/lib/python2.1/xml/sax/handler.py", line 38, in
fatalError
    raise exception
xml.sax._exceptions.SAXParseException: <unknown>:1:0: no element found




-Richard




More information about the Python-list mailing list