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

Charl P. Botha cpbotha at gmail.com
Wed Jun 15 16:40:59 EDT 2005


Dear VTK-developers and Python-heads,

The Python GIL, or global interpreter lock, prevents Python threads
from running concurrently [1].  It sounds strange, but it's true.

Due to the GIL, when one Python thread is calling a long-running VTK
method, no other Python threads are allowed to execute.  I've made a
small patch (attached) to vtkWrapPython.c that alleviates this problem
in the VTK Python wrappings by giving up the GIL just before the
actual call to VTK code and taking it back directly after.  I've
tested this, and now multiple VTK threads, invoked from Python, run
concurrently.  Python's thread-safety is not affected, as the GIL is
given up and taken back around a block containing no Python API calls.

I would like to apply this to VTK CVS.  It shouldn't affect any
existing code, but will improve the current state of affairs with
regards to multi-threaded VTK Python code.  Comments?

Thanks,
Charl

[1] http://docs.python.org/api/threads.html

-- 
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkWrapPython_GIL-friendly.diff
Type: application/octet-stream
Size: 1276 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20050615/270bbb82/attachment-0001.obj>


More information about the vtk-developers mailing list