[lxml-dev] Python crash with lxml use with multi-thread

Stefan Behnel stefan_ml at behnel.de
Wed Dec 19 12:37:37 CET 2007


Pedro Cardoso wrote:
> I am using lxml (just updated to version 1.3.6) on python 2.5, on a 
> windows XP machine.
> 
> I have a wrapper class for an XML file, and worked fine until I used it 
> on several threads. At that moment it will crash.
> 
> The piece of code I have it :
>             projectNode = self.dom.xpath('//Project[@Code="%s"]' 
> %projectCode)[0]
>             logger.debug("here")
>             previewsTask = self.dom.xpath('//Task[@Code="%s"]' % 
> taskData.xml_Code)[0]
>             logger.debug("here")
>             projectNode.replace(previewsTask, taskData.dom)
>             #projectNode.remove(previewsTask)
>             #projectNode.append(taskData.dom)
>             logger.debug("here")
>             self.save()
>             logger.debug("here")
>             return None
> The loggin is to know the last line to be called .
> 
> The last log msg is written, but the one right after the call to this 
> function is not, that makes me think the crash is on the return. There 
> should be no problem of thread safety, since I am using locks.
> 
> The crash seems to be on the return, and The calling sequence is :
>     thread 1 : append a node to xml and save
>     thread 2 : replaces node and save (the piece of code above)
>        At this moment it crash python !
> 
> Any idea of the problem ?

Have you read the FAQ section on threading?

http://codespeak.net/lxml/dev/FAQ.html#id1

Stefan



More information about the lxml-dev mailing list