"unhandled exception in thread"错误疑难解答



当我执行这段代码

import class3,thread
t3 = class3.test3
thread.start_new_thread(t3.func3,())

其中class3

class test3(object):
    def func3():
        while 1:
            print "working!!"

我得到一个错误:

启动的线程出现未处理异常

这个错误的含义是什么,我如何修复它?

调用它,看看会发生什么:

TypeError: unbound method func3() must be called with test3 instance as first argument (got nothing instead)

你必须让func3成为一个实例方法并初始化你的类:

class test3(object):
        def func3(self):
            while True:
                print "working!!"
t3 = test3()

或使func3变为staticmethod:

class test3(object):
    @staticmethod
    def func3():
        while True:
            print "working!!"

最新更新