[C++-sig] Release Python's lock before destructing pointer_holder
roman.yakovenko at gmail.com
Sat Mar 24 18:50:36 CET 2007
On 3/23/07, Gabriel Becedillas <gabriel.becedillas at corest.com> wrote:
> I'm wrapping a class whose destructor does some work on sockets that
> might take some time to complete, so I need to release Python's lock
> before calling the destructor.
> This instances are held via boost::shared_ptr. One way I could manage to
> do so is to declare a destructor for pointer_holder<> like this:
> PyThreadState* prev = PyThreadState_Swap(NULL);
> m_p = Pointer();
> There are 2 reasons why I don't like this solution. The first one is
> that I have to modify boost::python's code. The second is that I need
> this only for a certain class.
> Does anyone know a better/cleaner way to do this ?
boost::shared_ptr class takes custom deleter in constructor.
You can use it and solution provided in "How can I find the existing
PyObject that holds a C++ object?" Boost.Python FAQ to solve this
C++ Pytdhon language binding
More information about the Cplusplus-sig