Support extension module reloading
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Triaged
|
Wishlist
|
Unassigned |
Bug Description
A C program crashes after the second call to Py_Finalize() if lxml is used.
Tested with Python 2.5, 2.7 and 3.2. (etree.
The C code:
-[
#include <Python.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int x;
for(
{
printf(" + Py_Initialize (%d)...\n", x);
Py_Initialize();
printf(" + PyRun_SimpleStr
PyRun_
"print ' - etree.LXML_VERSION: ', etree.LXML_
"print ' - etree.parse()'\n" \
"tree = etree.parse(
"print ' - ok'\n");
printf(" + Py_Finalize.
Py_Finalize();
}
return 1;
}
]-
Compiled with:
shen139@
Using:
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
The output:
-[
shen139@
+ Py_Initialize (0)...
+ PyRun_SimpleStr
- etree.LXML_VERSION: (2, 3, 0, 0)
- etree.parse()
- ok
+ Py_Finalize...
+ Py_Initialize (1)...
+ PyRun_SimpleStr
- etree.LXML_VERSION: (2, 3, 0, 0)
- etree.parse()
Segmentation fault
]-
Using:
Version: 3.2 (r32:88445, Mar 25 2011, 19:26:27)
[GCC 4.5.2]
Platform: linux2
Backtrace:
-[
#0 0x001ec991 in PyObject_Malloc () from /usr/lib/
#1 0x001ea045 in _PyObject_New () from /usr/lib/
#2 0x00205cda in ?? () from /usr/lib/
#3 0x0020f3b5 in PyUnicodeUCS4_
#4 0x0020f963 in PyUnicodeUCS4_
#5 0x00213f29 in PyUnicodeUCS4_
#6 0x007eeca8 in ?? () from /usr/lib/
#7 0x00820b6c in ?? () from /usr/lib/
#8 0x00821210 in ?? () from /usr/lib/
...
...
#526 0x00821210 in ?? () from /usr/lib/
#527 0x00821210 in ?? () from /usr/lib/
#528 0x00821210 in ?? () from /usr/lib/
#529 0x00821210 in ?? () from /usr/lib/
#530 0x00821210 in ?? () from /usr/lib/
#531 0x00821210 in ?? () from /usr/lib/
...
...
.... many many many more......
]-
My guess is that this is simply because extension module unloading is not supported in CPython, especially not in 2.x.