crash (SEGV) in Py_EndInterpreter() in multithreaded program
Gernot Hillier
ghillie at suse.de
Wed Nov 13 11:22:02 EST 2002
Hi!
I experience a 80% reproducable SIGSEGV in a multithreaded app I wrote using
different embedded sub interpreters in its threads.
I have a C++ class (PClass) which encapsulates the sub-interpreters somehow
- it creates a new one in its constructor and deletes it in the destructor
(see below).
When 2 objects of this class are destroyed at nearly the same time thus
resulting in subsequent calls to Py_EndInterpreter(), I get the following
SIGSEGV in most cases:
> gdb application core.31889
[...]
Program terminated with signal 11, Segmentation fault.
[...]
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /usr/local/lib/python2.2/lib-dynload/time.so...done.
Loaded symbols for /usr/local/lib/python2.2/lib-dynload/time.so
#0 0x08078763 in class_dealloc (op=0x81a8624) at Objects/classobject.c:169
169 _PyObject_GC_UNTRACK(op);
(gdb) bt
#0 0x08078763 in class_dealloc (op=0x81a8624) at Objects/classobject.c:169
#1 0x080daefa in PyThreadState_Clear (tstate=0x816b7f0) at
Python/pystate.c:190
#2 0x080dab89 in PyInterpreterState_Clear (interp=0x81427e8) at
Python/pystate.c:77
#3 0x080dce1e in Py_EndInterpreter (tstate=0x816b7f0) at
Python/pythonrun.c:381
#4 0x0805c287 in ~PClass (this=0x81421d0) at pclass.cpp:123
When the 2nd object is destroyed some seconds later, everything seems to be
fine. It only crashes when the 2 objects are deleted within a short period
of time.
I've tried this with the SuSE RPMs of Python 2.2.1 and a self-built
Python-2.2.2 with the same result. :-(
I've absolutely no clue what goes wrong here. I would appreciate any
suggestion where to have a look. Perhaps some of you have an idea... TIA!!
Here's a very short snippet of the python related code in my class:
// Constructor, initializes Python sub-interpreter
PClass::PClass()
{
PyEval_AcquireLock();
py_state=Py_NewInterpreter();
PyEval_SaveThread();
}
// destructor, kills the Python sub-interpreter
PClass::~PClass()
{
PyEval_RestoreThread(py_state);
Py_EndInterpreter(py_state);
py_state=NULL;
PyEval_ReleaseLock(); // release lock
}
// thread code, runs Python function
void
PClass::run()
{
PyEval_RestoreThread(py_state);
PyObject_CallFunction(...)
PyEval_SaveThread();
}
--
Ciao,
Gernot
More information about the Python-list
mailing list