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

Sander Niemeijer niemeijer at science-and-technology.nl
Fri Jul 15 05:43:53 EDT 2005


On donderdag, jul 14, 2005, at 16:00 Europe/Amsterdam, David Cole wrote:

> My point is simply this: if something is *probably* going to be 
> incorrect, then force it to be incorrect early in the CMake 
> configuration stage rather than wasting people's time with build 
> settings that might not work. That's one of the beauties of CMake: you 
> can detect problems early and inform the developers about ways to 
> avoid them.
>
> While it may not be practical for everybody to upgrade their Python 
> installations, it is the safe thing to do if you need the threading 
> support being discussed here in conjunction with VTK. The safe thing 
> should be what happens by default.

If a user really _needs_ the threading support then the only viable 
option is to upgrade Python and use the latest version of VTK.
However, if a user doesn't need threading support then it would be nice 
if he could still continue to use his older Python with VTK (which 
should be perfectly workable).

>  People who need older Pythons combined with current VTK can always 
> force it to build on their own system from source code simply by 
> removing the check from the CMakeLists file.

This I find very ugly. IMHO a user should _never_ have to modify the 
source files of VTK (including CMakeLists.txt) in order to create a 
valid build of VTK.
I think the easiest solution is to add an additional check for 
threading in the cmake test you mentioned.
This would then become something like:

if threading enabled in VTK
   if python wrapping enabled in VTK
      if PYTHON_LIBRARY is found/set
         if python version < 23
	      display an error of the form "VTK_WRAP_PYTHON with threading 
enabled requires a minimum of Python version 2.3.\nYou should either:\n 
- upgrade python,\n - disable threading (this also requires a Python 
build with threading disabled), or\n - disable the Python wrapping in 
VTK (set VTK_WRAP_PYTHON to OFF).")

I have also tried to find a way to test whether Python is build with 
threading support and the easiest way I could find is to run Python and 
try to import the thread module (this is a build in Python module that 
is only included if Python was build with threading enabled): python -c 
'import thread'
The result code of this command will only be zero if the thread module 
was found.

If possible I think a test like the following would also be good to have

if python wrapping enabled in VTK
   if python threading enabled
     if threading disabled in VTK
       display an error of the form "VTK_WRAP_PYTHON with threading 
disabled requires a Python version that was build without threading 
support"
   else
     if threading enabled in VTK
       display an error of the form "VTK_WRAP_PYTHON with threading 
enabled requires a Python version that was build with threading support"

>  Or they can stick with an older build of VTK until they can upgrade 
> their Python...

This I don't understand. The current combination of VTK and Python with 
threading enabled is not working properly, so this is definitely not a 
'safe thing' to do.

> I'm just suggesting detecting problems as early as possible and 
> avoiding them by default. I don't mean to force any upgrades on 
> anybody... ;-)

Best regards,
Sander




More information about the vtk-developers mailing list