[C++-sig] Thread safety

dueymk dueymk at everestkc.net
Mon Dec 19 23:58:05 CET 2005

It turns out that using the PyGILState* functions was sufficient.  I also had to add:


to my module initialization code.  After that, it seems to work fine.


Patrick Hartling wrote:
> On 12/16/05, dueymk <dueymk at everestkc.net> wrote:
> I have a very similar case with my use of Boost.Python. With my code,
> a Python object will be instantiated and then handed off to the
> multi-threaded C++ library. The Python interpreter runs in the
> primordial thread, but the method invocations on the Python object are
> made from a different thread.
> My locking of the GIL has thus far been done before the call to
> boost::python::get_override() or any other Boost.Python functions. I
> changed my code so that the GIL is locked after the call to
> boost::python::get_override() as you have done above. I found that my
> code crashed at the first attempt of the C++ library's attempt to
> invoke a method of the Python object from a spawned thread. The crash
> occurred as a result of the call to boost::python::get_override()
> since it calls into the Python interpreter without the GIL being
> locked. I can provide a stack trace (from GDB) if you would like to
> see it.
>  -Patrick
> --
> Patrick L. Hartling
> http://www.137.org/patrick/
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig

More information about the Cplusplus-sig mailing list