By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,931 Members | 1,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,931 IT Pros & Developers. It's quick & easy.

xml.minidom and threads

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
su********@hotmail.com (Sunil Movva) wrote in message news:<91**************************@posting.google. com>...
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.


I agree this sounds as if minidom isn't thread safe. If so the
fastest way to get this fixed is to come up with a simple test case
and post a bug to:

http://sourceforge.net/tracker/?grou...73&atid=106473

--Uche
Jul 18 '05 #2

P: n/a
Sunil Movva <su********@hotmail.com> wrote:
So, I came to suspect if xml.minidom module is thread-safe.


No it isn't, but I doubt this is your problem as you don't seem to be
trying to access the DOM Nodes from multiple threads, let alone
concurrently. (Is there any good reason why you need to serialise and
re-parse between each thread?)

A SAXParseException is generally what it says on the tin, caused by
faulty syntax in the XML document being parsed. It is conceivable that
minidom's serialisation code at the second-thread-output stage is
producing something wrong; we'd have to have a look at the string the
third thread is trying to parse to find out what.

--
Andrew Clover
mailto:an*@doxdesk.com
http://www.doxdesk.com/
Jul 18 '05 #3

P: n/a
an********@doxdesk.com (Andrew Clover) wrote in message news:<2c**************************@posting.google. com>...
Sunil Movva <su********@hotmail.com> wrote:
So, I came to suspect if xml.minidom module is thread-safe.


No it isn't, but I doubt this is your problem as you don't seem to be
trying to access the DOM Nodes from multiple threads, let alone
concurrently. (Is there any good reason why you need to serialise and
re-parse between each thread?)

A SAXParseException is generally what it says on the tin, caused by
faulty syntax in the XML document being parsed. It is conceivable that
minidom's serialisation code at the second-thread-output stage is
producing something wrong; we'd have to have a look at the string the
third thread is trying to parse to find out what.


I was able to fix this problem. It has nothing to do with
thread-safety. The function xml.dom.minidom.parseString() throws
invalid token exception on trying to parse unicode strings. I forced
my app to use regular strings instead.

Thanks for the response.
-Sunil
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.