Garbage collector and threads
Nicolas Fleury
nid_oizo at yahoo.com_remove_the_
Mon Mar 1 12:33:59 EST 2004
Aahz wrote:
> What's "RAII"?
"Resource Acquisition Is Initialization"
It's a term frequently used in C++ to describe the use of constructor
and destructor for resource allocation/deallocation.
>>to __del__, whatever it is ref-counting or something else. Wouldn't a
>>class like CancellableThread, with a sub-class implemented cancel method
>>called when the object is not referred in any other thread be useful?
>
>
> Perhaps, but threading needs references to created threads in order to
> implement its functionality. You might try building your own thread
> constructs using ``thread`` directly.
I still don't know how to implement it. I can do something very simple
like:
class Canceller:
def __init__(self, thread):
self.thread = thread
def __del__(self):
self.thread.cancel()
self.thread.join()
but I can't merge the concept with a Thread class, because the self
passed to run would be a reference to the object... I don't know if a
language extension would be worth the effort or if there's a cool
solution I'm missing, but what is sure is that I write a lot of code to
cancel threads in finalizers of parent objects. I don't want deamon
threads so that everything is stopped cleanly, but at the same time it
is error-prone in a GUI application, because I risk to have the process
still running after a quit.
I just want a way to garantee that all my threads are cancelled when the
main thread is finished.
Regards,
Nicolas
More information about the Python-list
mailing list