[vtk-developers] Patch to vtkWrapPython.c to make wrapped Python code GIL-friendly

Sander Niemeijer niemeijer at science-and-technology.nl
Mon Jul 4 07:30:40 EDT 2005


On maandag, jul 4, 2005, at 12:38 Europe/Amsterdam, Prabhu Ramachandran 
wrote:

>>>>>> "SN" == Sander Niemeijer <niemeijer at science-and-technology.nl> 
>>>>>> writes:
>
> [...]
>     SN> My question is: is there a reason why (at least for Python 2.3
>     SN> and up) these functions are not used to properly grab the GIL?
>
>     SN> More info about the PyGILState functions can also be found in
>     SN> the PEP <http://python.fyxm.net/peps/pep-0311.html>
>
> I am not sure why this has not been accepted into the core.  Google
> does not seem to offer any help.

I am not sure what you mean. If you mean implementation of the PEP in 
Python, then this has been done AFAICS (the two new API functions 
mentioned are implemented now and seem to match the patch that is 
linked to from the PEP page <http://www.python.org/sf/684256>).

>     SN> Unfortunately I am not that familiar with Python threading
>     SN> issues, but shouldn't the following functions in
>     SN> vtkPythonUtil.cxx also be equipped with GIL grabbers?
>     SN> - vtkPythonVoidFunc
>     SN> - vtkPythonVoidFuncArgDelete
>     SN> - vtkPythonDeleteCommand::Execute
>
> Yes, I would think so.  I am not sure if Charl has looked at those.
> If not, good catch!

In that case, the attached patch can be used as a starting point for a 
final patch. Mind that the API's I am using are not available in Python 
versions prior to version 2.3, so the calls should probably be 
encapsulated with something like:

---
#if (PY_MAJOR_VERSION > 2) || ((PY_MAJOR_VERSION == 2) && 
(PY_MINOR_VERSION >= 3))
...
#endif
---

I don't know if a proper fix for the thread state initialization and 
locking exists for Python versions prior to 2.3, so it might be useful 
to instruct users to build Python/VTK/wxPython without threads if they 
want the callbacks in elder Python versions to work properly.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: VTK-cvs-20050628-patch
Type: application/octet-stream
Size: 1546 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20050704/fa1177c6/attachment-0001.obj>
-------------- next part --------------


Best regards,
Sander


More information about the vtk-developers mailing list