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

Charl P. Botha cpbotha at gmail.com
Wed Jul 13 12:50:50 EDT 2005

On 7/4/05, Sander Niemeijer <niemeijer at science-and-technology.nl> wrote:
> >     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 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>).

> 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) &&
> ...
> #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.

I've finally had some time to go look at the documentation, and this
would seem to be a good solution to the previous problem as well: i.e.
explicitly releasing the GIL before every long-running call.  With
Sander's patch applied, it looks like any VTK thread would be able to
call back into the main thread without any nasty effects.  Nice.

I'll merge my patch (or what's left of it - mostly just explicitly
releasing the GIL before long-running VTK methods) with Sander's work
and then try to break the resulting build.

Any more thoughts on what to do with users of Python < 2.3, besides
just warning somewhere in the documentation?  Even WITH the GIL lock
in place, things will crash...


charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/

c.p.botha ||at|| ewi.tudelft.nl - tu delft work-related email
cpbotha ||at|| cpbotha.net - everything else

More information about the vtk-developers mailing list