471,350 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

PyGILState_Release produces a seg fault

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/...ry/004890.html

(*) See line 1906->2019 at:
http://public.kitware.com/cgi-bin/vi...?annotate=1.80
Jan 10 '08 #1
0 1105

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Phil Powell | last post: by
4 posts views Thread by Randall Hopper | last post: by
1 post views Thread by Jean-David Beyer | last post: by
1 post views Thread by Kirill Simonov | last post: by
2 posts views Thread by Rolf Magnus | last post: by
3 posts views Thread by jr.freester | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.