Is my thread safe from premature garbage collection?

Sion Arrowsmith siona at chiark.greenend.org.uk
Thu Sep 1 09:16:19 EDT 2005


In article <df6h86$73b$2 at online.de>, Benjamin Niemann  <pink at odahoda.de> wrote:
>NutJob at gmx.net wrote:
>> However, in my current project I'm creating a bunch of threads which
>> are supposed to run until they've completed their run() method, and I'm
>> worried that if I do not keep references to these thread objects
>> around, the GC might happily delete them (and thereby kill my thread
>> routines maybe?) while they're not done yet. Is this fear justified?
>The threading module does already take care of keeping references to all
>running threads,

The implementation of threading.enumerate() would be entertaining if it
didn't.

Quite apart from which, I presume the OP's run() method looks something
like:
class MyThread(threading.Thread):
    def run(self):
        ...
So what is self if not a reference to the Thread object which is kept
around until run() has completed?

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |    -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump



More information about the Python-list mailing list