如果我有一个获得 threading.Thread 的类,我会使用 .start()
运行新线程class hello(threading.Thread):
def run():
print "hi"
print "bye"
所以这是一个线程,但是当我想在一个类中使用 2 个线程函数时?我该怎么做?
因为当你使用 .start() 它会在新线程中使用 run 函数。
最佳答案
使用 target
属性代替 Thread
构造函数:
class twothreads:
def t1(self):
print "Hi"
def t2(self):
print "Bye"
t = twothreads()
threading.Thread(target=t.t1).start()
threading.Thread(target=t.t2).start()
关于python - 多线程类(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18422131/