Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Can I use threads to concurrently access the lxml API?

API concurrently lxml threads
0
10 Posted

Can I use threads to concurrently access the lxml API?

0

Short answer: yes, if you use lxml 2.1 and later. Since version 1.1, lxml frees the GIL (Python’s global interpreter lock) internally when parsing from disk and memory, as long as you use either the default parser (which is replicated for each thread) or create a parser for each thread yourself. lxml also allows concurrency during validation (RelaxNG and XMLSchema) and XSL transformation. You can share RelaxNG, XMLSchema and (with restrictions) XSLT objects between threads. While you can also share parsers between threads, this will serialize the access to each of them, so it is better to .copy() parsers or to just use the default parser if you do not need any special configuration. Due to the way libxslt handles threading, applying a stylesheets is most efficient if it was parsed in the same thread that executes it. One way to achieve this is by caching stylesheets in thread-local storage. Warning: Before lxml 2.1, there were issues when moving subtrees between different threads.

0

Short answer: yes, if you use lxml 2.1 and later. Since version 1.1, lxml frees the GIL (Python’s global interpreter lock) internally when parsing from disk and memory, as long as you use either the default parser (which is replicated for each thread) or create a parser for each thread yourself. lxml also allows concurrency during validation (RelaxNG and XMLSchema) and XSL transformation. You can share RelaxNG, XMLSchema and (with restrictions) XSLT objects between threads. While you can also share parsers between threads, this will serialize the access to each of them, so it is better to .copy() parsers or to just use the default parser if you do not need any special configuration. Due to the way libxslt handles threading, applying a stylesheets is most efficient if it was parsed in the same thread that executes it. One way to achieve this is by caching stylesheets in thread-local storage. Warning: Before lxml 2.1, there were issues when moving subtrees between different threads. If y

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123