Boost logo

Boost Users :

Subject: [Boost-users] [Boost::Python] ensuring destructors are called when executing scripts
From: Andy Falanga (afalanga) (afalanga_at_[hidden])
Date: 2012-03-20 16:33:49

Hi everyone,

I'm working on an API that will be used in Python. I'm running some of my teams unit tests to test some new functionality. (These use the Python unit test framework though I admit I don't understand it.) The exposed class has an "interface" among its many member fields. This abstract class is, I believe, correctly defined. That is, the abstract class defines a virtual destructor. The derived classes define non-virtual destructors. When I use a smaller test python script that doesn't use the unit test framework for Python, all of these destructors seem to be called correctly. However, when using the unit test framework, this doesn't seem to be the case. I believe this to be problem anyway because when I use the unit test scripts, I get a BSOD. (The BSOD is because these classes use a propriety driver that was written by our team for underlying hardware.) When I call this class directly, in my other script, the destructors are called properly because things work and there's no BSOD.

I found a posting to some python support group where someone was having a similar problem. They mentioned that using Py_Finalize seemed to fix this but that it shouldn't be used with Boost. I'd like to know what's going on first of all. I'm not a python "anything". Before now, I've never used the language. Is there some way to ensure that C++ destructors are called? One of the respondents to the thread I mentioned said something about the interpreter still hold references and using a clear() method. However, the code he/she provided to illustrate wasn't python code at all but C++. It was as if they didn't understand the OP's request.

Any help is greatly appreciated.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at