I want to register every instances on my class in a dictionary, keys are one of the parameter.
This seems to work, but the __del__
function fails.
Here is the code :
class Test(object):
instances = {}
def __init__(self, id):
self.id = id
def launch(self):
print("launch")
Test.instances[self.id] = self
def __del__(self):
print("del")
del Test.instances[self.id]
And here are the different outputs I get:
>>> a = Test(25)
>>> del a
del
>>> a = Test(25)
>>> a.launch()
launch
>>> del a
>>>
I don't understand why this is happening, does someone has a suggestion?