Destructor in metaclass Singleton object

Viewed 1970

I'm modifying a legacy library that uses the singleton pattern through the metaclass approach.

The Singleton class, inheriting from type, defines de __call__ function.

Right now, my singleton object using this library are never deleted. I defined the __del__ method in the singleton classes and that function is never called.

Clarification: I have implemented one (meta)class named Singleton, that is used by several classes, using Singleton as __metaclass__.

For example, I have class A(object), that has __metaclass__ = Singleton. The A class has several members that I want to be destroyed when my program ends and the A object (the only one that can exist) is destroyed.

I tried defining __del__ method in A class, but it doesn't work.

1 Answers
Related