多线程类(python)
如果我有一个类得到了threading.Thread,我就用.start运行新线程 这是一个线程,但当我想在一个类中包含两个线程函数时?我该怎么做 因为当您使用.start时,它会在新线程中使用run函数。请改用线程构造函数的target属性:多线程类(python),python,multithreading,function,class,Python,Multithreading,Function,Class,如果我有一个类得到了threading.Thread,我就用.start运行新线程 这是一个线程,但当我想在一个类中包含两个线程函数时?我该怎么做 因为当您使用.start时,它会在新线程中使用run函数。请改用线程构造函数的target属性: class twothreads: def t1(self): print "Hi" def t2(self): print "Bye" t = twothreads() threading.Threa
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()
改为使用线程构造函数的target属性:
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()
谢谢,我不知道它可以那样用谢谢,我不知道它可以那样用