xml.minidom and threads

Sunil Movva sunilmovva at hotmail.com
Fri Mar 12 10:59:48 EST 2004


I have an application that uses xml to communicate between threads.
One of the threads in my app creates an xml message and sends it to a
second thread. This second thread parses the message and creates a new
xml message copying most part of the first message and sends it to a
third thread. The second thread was able to parse the message, while
the third thread is not able to parse the message that it received. I
am using minidom implementation of DOM to parse the messages. I am not
validating the messages.
So, I wrote this out to a file from the third thread and am able to
parse this from a stand alone non-threaded app.
I thought it might be an encoding issue, so I converted to utf-8 and
it still does not parse it.

The error message I get is here...
  File "KQMLMessage.py", line 224, in CreateMessage
    domDoc = xml.dom.minidom.parseString(message)
  File "//usr/lib/python2.2/xml/dom/minidom.py", line 967, in
parseString
    return _doparse(pulldom.parseString, args, kwargs)
  File "//usr/lib/python2.2/xml/dom/minidom.py", line 954, in _doparse
    toktype, rootNode = events.getEvent()
  File "//usr/lib/python2.2/xml/dom/pulldom.py", line 255, in getEvent
    self.parser.feed(buf)
  File "//usr/lib/python2.2/xml/sax/expatreader.py", line 149, in feed
    self._err_handler.fatalError(exc)
  File "//usr/lib/python2.2/xml/sax/handler.py", line 38, in
fatalError
    raise exception
SAXParseException: <unknown>:1:1: not well-formed (invalid token)

So, I came to suspect if xml.minidom module is thread-safe. 
Any suggestions or comments are welcome.

thanks,
Sunil



More information about the Python-list mailing list