M
Maurice LING
Hi,
I just have a simple question about threads. My classes inherits from
threading.Thread class. I am calling threading.Thread.run() method to
spawn a few threads to parallel some parts of my program. No thread
re-use, pooling, joining ... just plainly spawn a thread, run a routine.
So, at the end of run(), what happens to the thread? Just die?
While I am on it, can threading.Thread.run() accept any parameters?
My current implementation may be ugly. I have a class
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()
which is used in
class myClass: #using myThread
def __init__(self): pass
def aFunc(self): pass
def bFunc(self): pass
def runAll(self):
myThread(self.aFunc).start()
myThread(self.bFunc).start()
if __name__=='__main__': myClass().runAll()
Is this a good way?
Thanks and cheers
Maurice
I just have a simple question about threads. My classes inherits from
threading.Thread class. I am calling threading.Thread.run() method to
spawn a few threads to parallel some parts of my program. No thread
re-use, pooling, joining ... just plainly spawn a thread, run a routine.
So, at the end of run(), what happens to the thread? Just die?
While I am on it, can threading.Thread.run() accept any parameters?
My current implementation may be ugly. I have a class
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()
which is used in
class myClass: #using myThread
def __init__(self): pass
def aFunc(self): pass
def bFunc(self): pass
def runAll(self):
myThread(self.aFunc).start()
myThread(self.bFunc).start()
if __name__=='__main__': myClass().runAll()
Is this a good way?
Thanks and cheers
Maurice