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

John Zwinck jzwinck at gmail.com
Tue Dec 25 13:14:18 CET 2012


On 17/12/2012 03:25, Niall Douglas wrote:
> I won't go into too much detail here (search this list's archives),
> but in short there isn't just GIL management but also interpreter
> management, and on top of that both of those have to work right as
> exception throws happen plus policies must be instituted for things
> like container iterators (e.g. do you release GIL each iteration,
> every 10 iterations etc) and policies for multiple interpreter
> interactions (e.g. do we timeslice interpreters, or wait for one to
> go to i/o sleep first?).

The code I published is agnostic about iterators and iteration--the user 
must explicitly decide when the GIL is to be released and reacquired. 
I'm sure there could be fancier ways of doing it, e.g. with tags given 
to BPL's class_::def() for long-running methods.  But I didn't worry 
about that level of complexity--I think the simple solution offers 
benefits today, and can be expanded upon later.

Having multiple Python interpreters in one process seems fraught anyway, 
so I haven't really considered whether my code can (or should) support 
that.  I hope you'll agree it is not the common case.




More information about the Cplusplus-sig mailing list