1

如果我有一个有 threading.Thread 的类,我会使用.start()运行新线程

class hello(threading.Thread):
    def run():
        print "hi"
        print "bye"

所以这是一个线程,但是当我想要一个类中的 2 个线程函数时?我怎么做?

因为当你使用.start()时,它会在新线程中使用run函数。

4

1 回答 1

4

改为使用构造函数的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()
于 2013-08-24T19:12:39.510 回答