listing threads?
Cliff Wells
logiplexsoftware at earthlink.net
Thu Feb 28 17:11:09 EST 2002
On Thu, 28 Feb 2002 21:07:31 -0000
maximilianscherr wrote:
> in the docs theres the information, that i can list all active
> threads with threading.enumerate(), but i always just get the
> Mainthread displayed in the interpreter console.
>
> im doing somethin like:
>
> class test(threading.Thread):
> def t(self):
> print "self"
>
> te = test()
> te.start()
>
> then if i do threading.enumerate() i just get the mainthread int he
> list.
>
> so how can i now list all (active) threads?
If test really looks like that, then I'm guessing it exits before you call
enumerate, so all that is left is the main thread. Also, if you derive
from Thread, you need to tell it what it's running:
import threading
import time
class test(threading.Thread):
def __init__(self):
threading.Thread.__init__(self, target = self.t)
def t(self):
while 1:
time.sleep(1)
te = test()
te.start()
threading.enumerate()
--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308 (800) 735-0555 x308
More information about the Python-list
mailing list