Garbage collector and threads

Aahz aahz at pythoncraft.com
Tue Mar 2 00:16:50 CET 2004


In article <R4M0c.4365$mx4.107234 at nnrp1.uunet.ca>,
Nicolas Fleury  <nid_oizo at yahoo.com_remove_the_> wrote:
>Aahz wrote:
>> 
>> Right.  As I said, you have to use the ``thread`` module directly; you
>> can't use ``threading``.
>
>But even if I use "thread", I have no way to put the functionality in 
>one class if I want access the members in the running thread.

Huh?  I don't understand what you mean.

>>>I just want a way to garantee that all my threads are cancelled when the 
>>>main thread is finished.
>> 
>> So hold references to them and call the ``cancel()`` method yourself.
>
>That's a possible solution.  Make a custom Thread class with a cancel 
>method and with all instances registered somewhere.  At the end of the 
>main thread, I call something to cancel all these threads.  There's 
>however some problems with that solution:
>- Parent threads need to be cancelled before their children threads.

Why's that a problem?  Just hold references to the parent threads in the
main thread and cascade the cancels down.

>- It only works at the end of the main thread; it cannot be used at the 
>middle of an appplication.

Why?
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Do not taunt happy fun for loops. Do not change lists you are looping over."
--Remco Gerlich, comp.lang.python



More information about the Python-list mailing list