[lxml-dev] lxml 1.1 problems with python 2.3

Stefan Behnel behnel_ml at gkec.informatik.tu-darmstadt.de
Tue Nov 28 14:07:02 CET 2006


Hi Holger, Martijn,

Stefan Behnel wrote:
> Holger Joukl wrote:
>>> One way to work around this kind of problem would be to not release the
>>> thread
>>> context under 2.3. That should be simple to do, if we know the right
>>> places where we have to do this.
>> Better imho, so 2.3 users can still depend on lxml.
> 
> I'll try to come up with a fix then. Maybe it's enough to somehow disable the
> thread context calls to make lxml run single-threaded under 2.3. I'll have to
> rely on someone else to test it, though.

Ok, I committed this simple patch to the trunk that simply skips releasing and
re-acquiring the thread contexts under Python 2.3. I tried switching it on
under 2.5 and didn't find any problems in the tests, so please check if it
works on your side with 2.3, too.

If this works as expected, this would also give us a straight forward way to
compile lxml without threading by passing an option (--without-threading) to
setup.py and switching on the code section below via a compiler define.

Stefan


Index: src/lxml/etree_defs.h
===================================================================
--- src/lxml/etree_defs.h       (Revision 35078)
+++ src/lxml/etree_defs.h       (Arbeitskopie)
@@ -16,6 +16,20 @@
 #endif
 #endif

+/* Threading can crash under Python 2.3 */
+#if PY_VERSION_HEX < 0x02040000
+#ifndef WITHOUT_THREADING
+  #define WITHOUT_THREADING
+#endif
+#endif
+
+#ifdef WITHOUT_THREADING
+  #define PyEval_SaveThread() (NULL)
+  #define PyEval_RestoreThread(state)
+  #define PyGILState_Ensure() (PyGILState_UNLOCKED)
+  #define PyGILState_Release(state)
+#endif
+
 /* libxml2 version specific setup */
 #include "libxml/xmlversion.h"
 #if LIBXML_VERSION < 20621



More information about the lxml-dev mailing list