[lxml-dev] Error with thread

Frédéric Mantegazza mantegazza at ill.fr
Tue Oct 30 13:56:23 CET 2007


Le mardi 30 octobre 2007 13:36, Stefan Behnel a écrit :

> > Before using lxml, I was using lxml2, which is also based on libxml2
> > and libxslt, and I had not this thread problem.
>
> I assume you meant "libxml2", the Python wrapper around the libxml2 C
> library.

Yes, sorry.

>
> > Is this optimisation in your
> > C/python code, or in the original C libxslt code?
>
> We are talking about two optimisations here, one in libxslt and one in
> lxml. libxslt uses a hash table for XML names to avoid re-allocation of
> memory. AFAIR, the optimisation is that the dict used for the generated
> document inherits from the dict of the stylesheet document, which is
> treated as read-only dictionary fallback.
>
> The optimisation in lxml is that it uses one dictionary per thread, for
> all documents that are parsed in that thread. So, if you take a
> stylesheet that was parsed in one thread (and thus depends on the
> dictionary of that thread), and use it in a different thread that uses a
> different dictionary, you end up with a result document that tries to mix
> entries from different dictionaries and will therefore free some of them
> although they are still referenced in the dictionary of another thread. A
> sure way to crash your system.
>
> Sadly, the dictionary used by libxslt is not configurable, so all we can
> do is raise an exception if we detect this problem. I don't really see
> that as a disadvantage, as it is a fast and safe solution, and you can
> usually work around the restriction without major hassle.

Ok, I understand. I also prefer a fast XSLT solution ;o)

Thanks,

-- 
   Frédéric


More information about the lxml-dev mailing list