[lxml-dev] Proxy AssertionError in threaded tree traversal

Stefan Behnel stefan_ml at behnel.de
Wed Feb 14 21:29:41 CET 2007


Hi Holger,

Holger Joukl wrote:
> Is the compiled-to-C _registerProxy function an atomic operation regarding
> GIL-
> locking? Because inside it uses Python-API calls itself, wouldn't that mean
> there can be a thread change when in the function?

I think this is possible if there is any real Python code executed by the
interpreter, which can happen if you instantiate Python subclasses for
Elements (you had Python type classes, right?).

You can try putting a lock around the code executed in _elementFactory().
Acquire it before the call to getProxy() and release it after registerProxy().
Don't forget to also release it before any 'return', though. Take a look into
parser.pxi for an example.

Note, however, that this will give a noticeable slow down on Element
instantiation. If it works, it may still make sense to have a lock there if
you use enough threads to outweight the drop in performance.

Regards,
Stefan




More information about the lxml-dev mailing list