I have a threaded program in Python that works fine except that __del__ does not get called once the thread is running:
class tt(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.stop_event = threading.Event()
def __del__(self):
print "Deleting"
self.stop_event.set()
time.sleep(5)
def run(self):
self.stop_event.clear()
while not self.stop_event.isSet():
self.do_stuff()
threading.Thread.__init__(self)
def stop(self):
self.stop_event.set()
For example if I do
tc = aa()
del tc
It works fine (I get the deleting message pause etc). However if I do:
tc = aa()
tc.start()
del tc
Then the __del__ does not get run (Note it does execute __del__ when I do tc.start(); tc