[C++-sig] RAII for the GIL in Boost.Python?

John Zwinck jzwinck at gmail.com
Tue Dec 25 12:52:26 CET 2012


On 16/12/2012 22:58, Adam Preble wrote:
> Is the particular focus of your code on getting the GIL released during
> longer method invocations?  I don't have any sway with Boost or
> anything, so I'm just asking out of my own personal curiosities.  When I
> first saw the message, without seeing the code, I was wondering if you
> might have coincidentally created a scope-lock kind of thing for
> acquiring the GIL in the first place.

Yes, the main point is to provide a reasonably safe, RAII-style 
mechanism for releasing the GIL around long-running C++ functions.  But 
in addition to a class for releasing (and later reacquiring, hence 
RAII), I made a class for acquiring the GIL (if it is not held) and 
releasing it at the end.  This allows nesting: complex C++ computations 
can be done with the GIL released, yet some bits of C++ can call back 
into Python by using the second class to acquire the GIL when needed.

You needn't have sway with Boost to help here--simply reviewing the code 
and letting us know if it would help you would be great.




More information about the Cplusplus-sig mailing list