Python Threads - stopped vs. gone vs. Alive

RossGK rossgk at gmail.com
Wed May 28 12:01:01 EDT 2008


I'm a newbie to python threads, and playing with some simple client
server stuff and lots of print statements.

My server thread launched with
     self.worker = WorkerThread(self)
completes an interaction and then if I check on it's status with
     print "Status:", self.worker        I get        Status none


A client thread behaves differently. Launched as
      self.clientWorker( = ClientThreadself)
when it finishes it's work, I instead get:
     Status: <ClientThread(Thread-2, stopped)>

If I check the isAlive status on each of those, self.worker.isAlive
throws an exception, 'cause there is nothing there anymore to check
isAlive on.  But self.clientWorker comes back as False, since it is a
stopped thread and hasn't gone away (which I'd like it to after it
finishes its work).

So my question is when a thread finishes its work how do I more
predictably control whether it is just stopped, or goes away all
together?   I don't want to do a double nested 'if' statement to check
if it exists before I check if it's alive.




More information about the Python-list mailing list