[C++-sig] Release Python's lock before destructing pointer_holder

Gabriel Becedillas gabriel.becedillas at corest.com
Fri Mar 23 20:53:55 CET 2007


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:

pointer_holder::~pointer_holder()
{
	PyThreadState* prev = PyThreadState_Swap(NULL);
	PyEval_ReleaseLock();

	m_p = Pointer();

	PyEval_AcquireLock();
	PyThreadState_Swap(prev);
}

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 ?
Thanks.

-- 


Gabriel Becedillas
Developer
CORE SECURITY TECHNOLOGIES




More information about the Cplusplus-sig mailing list