4suite XSLT thread safe ?

Diez B. Roggisch deetsNOSPAM at web.de
Wed Jan 26 10:24:35 EST 2005


> If a thread that are using a XSLT processor looses the GIL within the
> transformation process and another one starts processing on the same
> processor will this work?
> 
> Will the half-way finished thread be in the way of the one starting the
> processing before the stoped thread are done.
> 
> I think that's what I ment. Can a XSLT processor object be shared
> between multiple threads?

No  - as a simple test reveals:

#The identity transform: duplicates the input to output
TRANSFORM = """<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>
"""

#And I don't even like Monty Python, folks
SOURCE1 = """<spam id="eggs">What do you mean "bleah"</spam>"""
SOURCE2 = """<spam id="eggs">I don't like spam</spam>"""

import threading
from Ft.Xml.Xslt import Processor
processor = Processor.Processor()
import time, sys
from Ft.Xml import InputSource

transform = InputSource.DefaultFactory.fromString(TRANSFORM,
"http://spam.com/identity.xslt")

processor.appendStylesheet(transform)

#Now the processor is prepped with a transform and ccan be used
#over and over for the same transform
results = []
source = InputSource.DefaultFactory.fromString(SOURCE1,
"http://spam.com/doc1.xml")
source2 = InputSource.DefaultFactory.fromString(SOURCE2,
"http://spam.com/doc2.xml")
threading.Thread(target=lambda:
results.append(processor.run(source))).start()
# comment the following line to make things crash.
time.sleep(5)
threading.Thread(target=lambda:
results.append(processor.run(source2))).start()

time.sleep(5)
print results


-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list