Do thread die?
Sybren Stuvel
sybrenUSE at YOURthirdtower.com.imagination
Sat Sep 17 05:31:47 EDT 2005
Maurice LING enlightened us with:
> So, at the end of run(), what happens to the thread? Just die?
Yep.
> While I am on it, can threading.Thread.run() accept any parameters?
Nope. Pass them to the constructor and remember them.
> class myThread(threading.Thread):
> def __init__(self, func):
> self.func = func
> threading.Thread.__init__(self)
> def run(self):
> print '%s function running' % self.func
> self.func()
You don't need to do this, since you can pass a callable object to the
Thread constructor. Read the first lines of
http://docs.python.org/lib/thread-objects.html again. That would
change your code to:
class myClass:
def __init__(self): pass
def aFunc(self): pass
def bFunc(self): pass
def runAll(self):
threading.Thread(self.aFunc).start()
threading.Thread(self.bFunc).start()
Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
More information about the Python-list
mailing list