2

When I execute this code

import class3,thread

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

where class3 is

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

I get an error:

Unhandled exception in thread started by <unbound method test3.func3>

What is the meaning of this error, and how do I fix it?

4

1 回答 1

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!!"
于 2013-03-25T23:05:55.450 回答