排除“线程中未处理的异常”错误

时间:2013-03-25 23:00:50

标签: multithreading python-2.7

当我执行此代码时

import class3,thread

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

其中class3

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

我收到错误:

  

< unbound method test3.func3>

启动的线程中未处理的异常

此错误的含义是什么,我该如何解决?

1 个答案:

答案 0 :(得分:0)

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

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!!"