[lxml-dev] Error with thread
Stefan Behnel
stefan_ml at behnel.de
Tue Oct 30 09:35:25 CET 2007
Frédéric Mantegazza wrote:
>> Try preparing the stylesheets in the main thread. Or, if you do not
>> control the main thread, consider creating them on the fly and maybe
>> caching them in thread local storage.
>
> Mmmm, I can't do that, as:
>
> 1) I would have to create the stylesheets every second (I use them to output
> datas during instrument scans, and I have 5 or 6 different stylesheets,
> used for screen output, and different files formats outputs);
>
> 2) I can't cache them, as a new thread is created for each new point of the
> scan (Pyro mecanism).
>
> I have to find another solution, by adding some new methods and propagate
> the new params, without creating a new stylesheet.
I think that's the best and most efficient way to do it. Generalise your
stylesheets to make them configurable through parameters so that you can
instantiate them once and then pass parameters that tell the stylesheet how to
behave in this specific thread for the task at hand. With a bit of thinking,
you should end up with a small set of different stylesheets (5-6 sounds
reasonable to me) and some parameters for them that make them work in all use
cases.
If you want to specialise the stylesheets even further, consider creating them
(partially) programmatically by adapting the XSL tree to your needs (adding
xsl:include tags or templates as you see fit), then create the XSLT instances
and store them in a read-only dictionary, maybe addressed by a tuple of
parameters or whatever you find appropriate.
Stefan
More information about the lxml-dev
mailing list