Hi everyone,
I just discovered, correct me if I'm wrong, that as long as a
threading.Threa d is running, its destructor will not be called, because
it is referring to himself. So if I have something like:
class MyThread(thread ing.Thread):
def __init__(self):
self.cancelEven t = threading.Event ()
threading.Threa d.__init__(self )
def __del__(self):
self.cancel()
def run(self):
self.cancelEven t.wait()
def cancel(self):
self.cancelEven t.set()
I must call cancel from the outside if I want the destructor to be
called (note that I don't want deamon threads). I can make a wrapper
over threading.Threa d to have the behaviour I want: have a thread with
__del__ called when it is not referred by another thread. But my
question is, and I don't have an overall vision of the issue at all,
should that be the default behaviour anyway?
Regards,
Nicolas
I just discovered, correct me if I'm wrong, that as long as a
threading.Threa d is running, its destructor will not be called, because
it is referring to himself. So if I have something like:
class MyThread(thread ing.Thread):
def __init__(self):
self.cancelEven t = threading.Event ()
threading.Threa d.__init__(self )
def __del__(self):
self.cancel()
def run(self):
self.cancelEven t.wait()
def cancel(self):
self.cancelEven t.set()
I must call cancel from the outside if I want the destructor to be
called (note that I don't want deamon threads). I can make a wrapper
over threading.Threa d to have the behaviour I want: have a thread with
__del__ called when it is not referred by another thread. But my
question is, and I don't have an overall vision of the issue at all,
should that be the default behaviour anyway?
Regards,
Nicolas
Comment