PyGILState_Release produces a seg fault

M

mathieu

Hello and happy new year folks,

I am experiencing a seg fault while using the python interface to
the VTK library (debian oldstable, python 2.3). The VTK library is
wrapped by a custom mechanism to provide a python API. In particular
they implemented a way so that a python function can be called in
response to an event(*). Basically all the code is doing is:

{
PyGILState_STATE state = PyGILState_Ensure();
// construct arglist from C++ args:
...
// call python function:
result = PyEval_CallObject(this->obj, arglist);

PyGILState_Release(state); // crash happens here
}

However the event being triggered from the C++ layer is done from
multiple threads. After reading :

http://docs.python.org/api/threads.html

I tought that the VTK-python layer was simply missing a call to :
PyEval_InitThreads() just before Py_InitModule(), but now my python
shell appears as hung ! The only solution I found is that if I comment
out the function calls PyGILState_Ensure/PyGILState_Release then
everything goes smoothly.

Am I reading the docs backward ? I do need to keep the call to
PyGILState_Ensure/PyGILState_Release, right ?

I am also copying the log from valgrind (VTK lib untouched, no call
to PyEval_InitThreads), UpdateProgress being the function called from
multiple threads:

==20066== Thread 2:
==20066== Invalid read of size 4
==20066== at 0x403232A: sem_post@@GLIBC_2.1 (in /usr/lib/debug/
libpthread-2.5.so)
==20066== by 0x80B0D53: PyEval_ReleaseLock (in /usr/bin/python2.4)
==20066== by 0x80DDB20: PyGILState_Release (in /usr/bin/python2.4)
==20066== by 0x45C7AB4: vtkPythonCommand::Execute(vtkObject*,
unsigned long, void*) (vtkPythonUtil.cxx:2016)
==20066== by 0x483C0DF: vtkSubjectHelper::InvokeEvent(unsigned
long, void*, vtkObject*) (vtkObject.cxx:547)
==20066== by 0x483C18E: vtkObject::InvokeEvent(unsigned long,
void*) (vtkObject.cxx:713)
==20066== by 0x4E67E6A: vtkAlgorithm::UpdateProgress(double)
(vtkAlgorithm.cxx:115)

Thanks,
-Mathieu

Original post:
http://public.kitware.com/pipermail/vtk-developers/2008-January/004890.html

(*) See line 1906->2019 at:
http://public.kitware.com/cgi-bin/viewcvs.cgi/Common/vtkPythonUtil.cxx?annotate=1.80
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top